Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Sep 2002
    Thanked 1 Time in 1 Post

    [vb] How do you pull a specific string from an html doc?


    Ive been working on this program for some time now and ive run into a snag, I need to be able to pull a certain string from an html document and set up a conditional statement like.

    If string="text" then
    Elseif string="bleh" then
    End If

    Ive done alot of searching on the net and have found one example of how to find text in an html document, the code is below.
     Private Sub Command1_Click()
        'The command you would use for this
        'function should look a bit like
        If WebPageContains( _
        "Hello how are you today?") = True Then
        MsgBox "The webpage contains the text"
        End If
        End Sub
        Private Function WebPageContains(ByVal s As String) As Boolean
        Dim i As Long, HTMLElement
        'Change the "WebBrowser1" to the
        'name of your Web Browser in the
        'next two lines of code.
        For i = 1 To WebBrowser1.Document.All.length
        Set HTMLElement = _
        If Not (HTMLElement Is Nothing) Then
        If InStr(1, HTMLElement.innerHTML, _
        s, vbTextCompare) > 0 Then
        WebPageContains = True
        Exit Function
        End If
        End If
        Next i
        End Function
    Only ive changed it to if the text is equal to something then it performs an action, the snag I run into is this, If the string im looking for has a space in it then only the first word before the space is found, not the whole string which is what I need, is there a way that I could perhpas modify the above code to include spaces in the search? Im sorry for the sort of broken up in a rush way I typed this but Ive written out about 7000 lines of code in a day and im a bit fryed and this is like the last thing that I need so Im a bit frustrated.
    When traveling down the road of life, Try not to drag your face in the gravel.

  • #2
    Regular Coder
    Join Date
    Aug 2004
    Thanked 0 Times in 0 Posts
    *this message will self destruct in n-seconds*


    Posting Permissions

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