Results 1 to 5 of 5

Thread: loop help

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jul 2009
    Posts
    29

    loop help

    hey every1
    i need to know how to make this code work with a do while loop

    the statement is that

    Code:
    do while webbrowser1.locationurl="www.xxxxxxxxxxxxxxx.com"
    Code:
    Private Sub Command1_Click()
        Dim strfindword As String
            strfindword = InputBox("What are you looking for?", "Find", "") ' what word to find?
                If WebPageContains(strfindword) = True Then 'check if the word is in page
                    MsgBox "The webpage contains the text" 'string is in page
                Else
                    MsgBox "The webpage doesn't contains the text" 'string is not in page
                End If
    End Sub
    Private Function WebPageContains(ByVal s As String) As Boolean
        Dim i As Long, EHTML
        For i = 1 To WebBrowser1.Document.All.length
            Set EHTML = _
            WebBrowser1.Document.All.Item(i)
     
     
            If Not (EHTML Is Nothing) Then
                If InStr(1, EHTML.innerHTML, _
                s, vbTextCompare) > 0 Then
                WebPageContains = True
                Exit Function
            End If
        End If
    Next i
    End Function
    Private Sub Form_Load()
        WebBrowser1.Navigate2 "www.msn.com"
    End Sub
    so the bottom line is that i wanna do all the above code with a loop that is:
    Code:
    do while webbrowser1.locationurl="www.xxxxxxxxxxxxxxx.com"

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,479

    Re: loop help

    the problem is the loop will run forever. there's nowhere that the webbrowser navigates away from the original url.
    you can't put the Form_Load event in a loop. + you seem to be using pre .net style event declarations.

    if you can explain exactly what you're trying to do, i'll try to help you.

    edit: i just noticed. this isn't a .net question. i don't use pre .net vb

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Jul 2009
    Posts
    29

    Re: loop help

    help would be really appreciated...... :S

  4. #4
    Hyperactive Member deathfxu's Avatar
    Join Date
    Mar 2009
    Location
    USA
    Posts
    279

    Re: loop help

    It seems to me that you are just trying to search the webpage for desired text, and you want it to stop searching if they navigate away from the page in the middle of searching (if I am understanding correctly):

    vb Code:
    1. 'In global declarations
    2. Dim NavTarget As String
    3.  
    4. 'In the form
    5. Private Sub webbrowser1_ProgressChange(ByVal Progress As Long, ByVal ProgressMax As Long)
    6.     NavTarget = webbrowser1.LocationURL
    7. End Sub
    8.  
    9. Sub webpageFind(FindText As String)
    10. Dim Results As New Collection
    11. Dim pageHTML As String
    12. Dim lastPos As Long
    13. Dim startURL As String
    14.  
    15. pageHTML = WebBrowser1.document.documentElement.innerHTML
    16. startURL = NavTarget
    17. lastPos = InStr(1, pageHTML, FindText)
    18. Do While lastPos > 0 and startURL = NavTarget
    19.     Results.Add lastPos
    20.     lastPos = InStr(lastPos + 1, pageHTML, FindText)
    21.     DoEvents
    22. Loop
    23. 'all the locations are stored in the Results collection now to do with as you want
    24. End Sub

    Lemme know if you have any questions. Good luck!

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Jul 2009
    Posts
    29

    Re: loop help

    im a bit confused...
    can u help me deploy this code...
    im bit of a newbie so an example would be amazing

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