Results 1 to 2 of 2

Thread: need help with loop in search engine finder code

  1. #1

    Thread Starter
    Addicted Member jalexander's Avatar
    Join Date
    Jan 2011
    Location
    Memphis, TN
    Posts
    160

    Question need help with loop in search engine finder code

    Ran into a problem. My for loop seems to stop after just for the task. I can't seem how to get it to continue on, I've used this type of loop many times and have never had this problem. Any suggestions?


    Code:
    Imports System.Net
    Imports System.Text.RegularExpressions
    Public Class Form1
        Dim sites As String = Nothing
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
      ListBox1.Items.AddRange(TextBox1.Text.Split(Environment.NewLine))
      TextBox1.Clear()
        End Sub
    
        Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
      BackgroundWorker1.RunWorkerAsync()
        End Sub
        Private Sub BackgroundWorker1_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork
      Dim pages As Integer = 1
      Dim p As Integer = 0
      Dim source As String
      For i = 0 To ListBox1.Items.Count - 1
        RichTextBox1.Text = RichTextBox1.Text + ListBox1.Items.Item(i)
        Do Until p = NumericUpDown1.Value
        Dim wc As New WebClient
        source = wc.DownloadString("http://www.bing.com/search?q=" & ListBox1.Items.Item(i) & "&go=&qs=n&sk=&sc=4-13&first=" & pages & "&FORM=PERE")
        sites = sites + source
        links(i)
        pages += 10
        p += 1
        Loop
        source = Nothing
      Next
        End Sub
        Private Sub links(ByVal i As Integer)
      Dim links As MatchCollection = Regex.Matches(sites, "(http|https):\/\/([\w\-_\.]+)+([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])?", RegexOptions.Singleline + RegexOptions.IgnoreCase)
      For Each link As Match In links
        Dim value As String = link.Groups(0).Value
        If value.Contains(ListBox1.Items.Item(i)) Then
        RichTextBox1.Text = RichTextBox1.Text + value + vbNewLine
        End If
      Next
        End Sub
    End Class
    dim jenn as geek = true
    Learning ~ Visual Basic 2010 ~ in free time between college/work -
    currently looking for a 'programming buddy' / 'coder friend' / and or 'mentor'. p.m. me if you
    have ANY free time AT ALL I'm like 33% of a novice level ~ willing 2 listen/learn +
    i am totally super motivated & promise to make an effffin amazing protege!!! #swag

    | -_-_- -_-_- |
    ...W.T..F!?.....
    ||| Matter on the atomic/quantum level isn't solid or even matter at all. It can also exist in at least 2 places simultaneously (demonstrated in lab). It's position can only be established when it's actually observed. If we turn our back on it... it goes back to a wave form. History show's that every previous generation (since the beginning of time) got almost everything wrong. Then it might very well stand to reason that up is down & right can be wrong. Admit it.. our combined perception of reality is just that, we know absolutely nothing of actual reality & to think we do is simply subscribing to a "ignorance is bliss" mantra |||

  2. #2
    Hyperactive Member
    Join Date
    Jan 2002
    Location
    UK, Suffolk
    Posts
    319

    Re: need help with loop in search engine finder code

    At first glance it looks to me like, you need to reset 'p' to when you drop out of the 'Do Until loop'. On the Next 'For Loop' 'p' is already equal to NumericUpDown.Value and so won't perform the Do Until.

    Where you have source = nothing, add on a new line p = 0 and see if that works


    Cheers

    Dan

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width