Archive

Posts Tagged ‘WebBrowser Object’

Web Browsing and Form Completion with Visual Basic 6 – Part 2

March 22nd, 2006

In the last installment of this series, we looked at how you gain access to the HTML code of a web page using the Visual Basic 6 WebBrowser object.   That’s a good first step toward doing something a bit more interesting, which is completing a web form using the VB6 WebBrowser object.

Last time around we wrote a simple program that took a look at my home page and showed you the HTML. Now, we’re going to use the information we learned there to figure out how to automatically search my site for anything mentioning Visual Basic.

The first step is to identify the form used on my site for the search function. As it turns out, the search form on my site is contained in the following code:

<FORM action=index.php
method=post>
<DIV class=searchblock
id=searchblock>Enter Keywords: <INPUT class=inputbox
onblur="if(this.value=='') this.value='search...';"
style="WIDTH: 128px" onfocus="if(this.value=='search...')
this.value='';" size=15 value=search... name=searchword>
<INPUT type=hidden value=search name=option
<DIV
align=left><INPUT class=button style="WIDTH: 35px"
type=submit value=GO> </DIV></DIV> </FORM>

Since this is the first form in this particular web document, we should be able to access it as “Forms(0)” through the WebBrowser.Document object’s “Forms()” collection. (If it had been the second form to appear on the page, we’d use “Forms(1)”, etc.)   To see if this is the case, we add the following code to the WebBrowser1_DocumentComplete event to read as follows:

Private Sub
WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As
Variant)
 If URL <> txtURL.Text Then Exit Sub
 If pDisp <> WebBrowser1.Object Then Exit Sub 

txtHTMLDisplay.Text = WebBrowser1.Document.Body.innerhtml 

txtURL.Text = WebBrowser1.LocationURL 

WebBrowser1.Document.Forms(0).Item(0).Value = "Visual Basic"
End Sub

admin VB and VBScript , , , , , , , , ,