Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to search for the keyword in the webbrowser added in the form

Status
Not open for further replies.

anu2712

Programmer
Jun 13, 2001
5
IN
Hi,

I am using VB-6, I have a form which has the search button and the text box to enter in the search keyword.
I also have a webbrowser added in the same form,
The keyword entered in the search text box has to search for the word matching in the webbrowser which is displayed.
webbrowser contains the html page which is created by me and is on my local server.

Pls tell me as to how to search for the keyword in the html page.

thanks,
Anu
 
First, I assume that you want to manipulate the HTML on the page. The good news is that it is easy once you know how and ESPECIALLY if you are the author of the page. First thing. Use the ID= keyword on all the HTML elements of interest to you, if not ALL. It makes getting to the element a lot easier. Now get over to Click on Libraries / Web Workshop / DHTML, HTML, & CSS / DHTML Object Model / W3C Document Model / click on Specification / click on chapter 2.
During all this realize that you can gert to these elements either BY NAME, BY ID or through a collection for items like SCRIPT that have no name and have not been ssupplied with an ID. You can actually change any element INCLUDING SCRIPT through these elements.

I've only just begun, Jun 15 but I have the following.
Code:
Private Sub Signon()
    Dim objDoc          As HTMLDocument
    Dim objElements     As Object
    Dim objElement      As Object
    Dim objScripts      As Object
    Dim I               As Long
    Dim strText         As String
    On Error Resume Next
    If WebBrowser1.Busy Then Exit Sub
    Do
        Set objDoc = WebBrowser1.Document
        If Err.Number <> 0 Then Exit Do
        
        '*****
        '* Last Name
        '*****
        ' No ID but finds NAME
        Set objElement = objDoc.All(&quot;SUBJECT_LAST_NAME&quot;)
        If Err.Number <> 0 Then Exit Do
        objElement.Value = &quot;HELLBERG&quot;
        If Err.Number <> 0 Then Exit Do
        
        '*****
        '* State - ListBox
        '*****
        ' No ID but finds NAME
        Set objElements = objDoc.All(&quot;CUR_STATE&quot;)
        If Err.Number <> 0 Then Exit Do
        For I = 0 To objElements.length - 1
            Set objElement = objElements(I)
            If objElement.Value = &quot;VA&quot; Then
                objElement.Selected = True
                Exit For
            End If
        Next
                
        '*****
        '* Alert
        '*****
        ' No ID and no NAME - Replaces 1st script
        Set objElements = objDoc.scripts
        If Err.Number <> 0 Then Exit Do
        For Each objElement In objElements
            strText = objElement.Text
            objElement.Text = &quot;function alertFormError(errorMsg){};&quot;
            If Err.Number <> 0 Then Exit Do
            If Len(strText) > 0 Then
                Debug.Print strText
            End If
            exeit for 
        Next
        
        '*****
        '* GO button
        '*****
        ' click on the button
        Set objElements = objDoc.getElementsByName(&quot;CONTINUE&quot;)
        If Err.Number <> 0 Then Exit Do
        Set objElement = objElements(0)
        If Err.Number <> 0 Then Exit Do
        If Not (objElement Is Nothing) Then
            objElement.Click
        End If
    Exit Do: Loop
    
    If Err <> 0 Then MsgBox Err.Description: Exit Sub
End Sub
Don't hesitate to ask. This is actually easy ONCE you have the DOCS.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top