I'm looking to be able to open a .txt file (with sites 1 per line) and visit all of those sites silently while moving a progress bar. Im gonna be honest, I have no idea how to even start this Any help would be appreciated.
Get file path
Open file
Loop through lines
Read line
Navigate to website
Stop Loop
Close file
ProgressBar1.Maximum = ListBox1.Items.Count - 1
ProgressBar1.Value = 0
For a As Integer = 0 To ListBox1.Items.Count - 1
Dim link As String = ListBox1.Items.Item(a)
Try
VisitURL(link)
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try
If ProgressBar1.Value <> ProgressBar1.Maximum Then
ProgressBar1.Value = ProgressBar1.Value + 1
End If
Next
MessageBox.Show("Done")
End Sub
Sub VisitURL(ByVal SomeURL As String)
Dim request As WebRequest = WebRequest.Create(SomeURL)
Dim response As WebResponse = request.GetResponse()
End Sub
'Reset the progressbar
ProgressBar1.Value = 0
For a As Integer = 0 To ListBox1.Items.Count - 1
Dim link As String = ListBox1.Items.Item(a)
Try
VisitURL(link)
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try
Dim PercentComplete As Integer = (a/(ListBox1.Items.Count -1) * 100)
Progressbar1.Value = PercentComplete
Next
MessageBox.Show("Done")
End Sub
The progress bar works best (in my experience) if you translate the values to percentage of completion. So we take the number of processed links (a) and divide it by the total links (ListBox1.Items.Count -1) and then multiple that result by 100 to get percentage. Assign it to the current value and there ya go.
I have to admit I am not sure about how to access the websites, what you have looks fine. I have done a little bit, and have used something similar. What are you planning when you get a web response? Is there information to process?VB.NET:'Reset the progressbar ProgressBar1.Value = 0 For a As Integer = 0 To ListBox1.Items.Count - 1 Dim link As String = ListBox1.Items.Item(a) Try VisitURL(link) Catch ex As Exception MessageBox.Show(ex.ToString) End Try Dim PercentComplete As Integer = (a/(ListBox1.Items.Count -1) * 100) Progressbar1.Value = PercentComplete Next MessageBox.Show("Done") End Sub