Question Visit List of URLs

david84

Member
Joined
May 6, 2010
Messages
20
Programming Experience
Beginner
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 :p Any help would be appreciated.
 
Start with pseudo code
VB.NET:
Get file path

Open file 
    Loop through lines
          Read line
          Navigate to website
     Stop Loop
Close file

That's how I would start out. To make it even easier for yourself, start with that and flesh it out to be a little less vague at each step and you'll have a plan for code in no time.
 
So I have this, but only the first site is visited. Can anybody suggest a better way of visiting, and moving the progress bar?
VB.NET:
  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
 
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.

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
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?
 
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.

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
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?

Thanks for this, I will try it when I get my PC with VB back. And there's nothing to process, it just needs to visit the link.
 
Back
Top