lawa543
Cloud Automation Wizard
2
MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1
300 XP
Introduction:
Hello and welcome to a tutorial on how to make a single file downloader in Visual Basic. A word of advise; once you understand how this program works I would recommend adding the function to a new thread so the UI doesn't freeze while it is downloading.
Steps of Creation:
Step 1:
First we want to get a direct download link to a file, you can get this by downloading a file then going to your download manager (in chrome, firefox or any other browser/application) and copying the download link that is shown, I will be using a direct download link from the official website to download the English Windows 64Bit WinRar Application (link: http://www.rarlab.com/rar/winrar-x64-500.exe)
Step 2:
Now make a form with a textbox (direct download link) and a button to begin the process. I have kept the default names of textbox1 and button1 as we can easily tell the difference.
Step 3:
Next double click on button1 to get to the clicked event code, and add this:
First we are getting the returned string from a function which we have not yet created called "checkURL" which is going to check the download link is in the correct format. Once it has the URL it is going to ask for a save location path and name and download the file to that directory. If it goes successfully it will output "Finished!", otherwise it will output "Failed".
Step 4:
Finally we want to make our checkURL function. As mentioned above, it will check the direct download link is in the correct format.
Project Complete!
Below is the full source and download to the files...
Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.
Virus note: All files are scanned once-a-day by SourceCodester.com for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.
FOR YOUR OWN SAFETY, PLEASE:
1. Re-scan downloaded files using your personal virus checker before using it.
2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.
Download
Hello and welcome to a tutorial on how to make a single file downloader in Visual Basic. A word of advise; once you understand how this program works I would recommend adding the function to a new thread so the UI doesn't freeze while it is downloading.
Steps of Creation:
Step 1:
First we want to get a direct download link to a file, you can get this by downloading a file then going to your download manager (in chrome, firefox or any other browser/application) and copying the download link that is shown, I will be using a direct download link from the official website to download the English Windows 64Bit WinRar Application (link: http://www.rarlab.com/rar/winrar-x64-500.exe)
Step 2:
Now make a form with a textbox (direct download link) and a button to begin the process. I have kept the default names of textbox1 and button1 as we can easily tell the difference.
Step 3:
Next double click on button1 to get to the clicked event code, and add this:
- Private
Sub
Button1_Click(sender As
Object
, e As
EventArgs) Handles Button1.Click
- Dim
url As
String
= checkURL()
- Try
- Dim
fo As
New
SaveFileDialog
- fo.Filter = "Executable File|.exe|All Files|*"
- fo.FilterIndex = 1
- fo.RestoreDirectory = True
- fo.ShowDialog()
- Dim
path As
String
= fo.FileName
- My.Computer.Network.DownloadFile(url, path)
- MsgBox("Finished!"
)
- Catch ex As
Exception
- MsgBox("Failed"
)
- End
Try
- End
Sub
First we are getting the returned string from a function which we have not yet created called "checkURL" which is going to check the download link is in the correct format. Once it has the URL it is going to ask for a save location path and name and download the file to that directory. If it goes successfully it will output "Finished!", otherwise it will output "Failed".
Step 4:
Finally we want to make our checkURL function. As mentioned above, it will check the direct download link is in the correct format.
- Private
Function
checkURL()
- Dim
s As
String
= TextBox1.Text.ToLower()
- If
(s.StartsWith("http://www."
) Or
s.StartsWith("https://www."
)) Then
- Return s
- ElseIf
(s.StartsWith("http://"
)) Then
- If
(s.Contains("www."
)) Then
- s = "http://www."
& s.Substring(1, s.Count - 1)
- TextBox1.Text = s
- Return s
- Else
- s = "http://www."
& s.Substring(7, s.Count - 7)
- TextBox1.Text = s
- Return s
- End
If
- ElseIf
(s.StartsWith("https://"
)) Then
- If
(s.Contains("www."
)) Then
- s = "https://"
& s.Substring(12, s.Count() - 12)
- TextBox1.Text = s
- Return s
- Else
- s = "https://www."
& s.Substring(8, s.Count - 8)
- TextBox1.Text = s
- Return s
- End
If
- Else
- If
(s.StartsWith("www."
)) Then
- s = "http://www."
& s.Substring(4, s.Count() - 4)
- TextBox1.Text = s
- Return s
- Else
- s = "http://www."
& s
- TextBox1.Text = s
- Return s
- End
If
- End
If
- End
Function
Project Complete!
Below is the full source and download to the files...
- Public
Class Form1
- Private
Sub
Button1_Click(sender As
Object
, e As
EventArgs) Handles Button1.Click
- Dim
url As
String
= checkURL()
- Try
- Dim
fo As
New
SaveFileDialog
- fo.Filter = "Executable File|.exe|All Files|*"
- fo.FilterIndex = 1
- fo.RestoreDirectory = True
- fo.ShowDialog()
- Dim
path As
String
= fo.FileName
- My.Computer.Network.DownloadFile(url, path)
- MsgBox("Finished!"
)
- Catch ex As
Exception
- MsgBox("Failed"
)
- End
Try
- End
Sub
- Private
Function
checkURL()
- Dim
s As
String
= TextBox1.Text.ToLower()
- If
(s.StartsWith("http://www."
) Or
s.StartsWith("https://www."
)) Then
- Return s
- ElseIf
(s.StartsWith("http://"
)) Then
- If
(s.Contains("www."
)) Then
- s = "http://www."
& s.Substring(1, s.Count - 1)
- TextBox1.Text = s
- Return s
- Else
- s = "http://www."
& s.Substring(7, s.Count - 7)
- TextBox1.Text = s
- Return s
- End
If
- ElseIf
(s.StartsWith("https://"
)) Then
- If
(s.Contains("www."
)) Then
- s = "https://"
& s.Substring(12, s.Count() - 12)
- TextBox1.Text = s
- Return s
- Else
- s = "https://www."
& s.Substring(8, s.Count - 8)
- TextBox1.Text = s
- Return s
- End
If
- Else
- If
(s.StartsWith("www."
)) Then
- s = "http://www."
& s.Substring(4, s.Count() - 4)
- TextBox1.Text = s
- Return s
- Else
- s = "http://www."
& s
- TextBox1.Text = s
- Return s
- End
If
- End
If
- End
Function
- End
Class
Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.
Virus note: All files are scanned once-a-day by SourceCodester.com for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.
FOR YOUR OWN SAFETY, PLEASE:
1. Re-scan downloaded files using your personal virus checker before using it.
2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.
Download
You must upgrade your account or reply in the thread to view the hidden content.