In this sample I will fill the altavista search box, with the WebBrowser control. Below I will list some subs and functions which are used in this sample.
Open a new project (standard exe) and place a WebBrowser control, a textbox, and a command button on form1. Make sure you also have an reference to mshtml.tlb.
Add the following code to form1:
Private Sub Command1_Click() 'go to the altavista (text) search page 'Wait until page is loaded 'Make doc reference to the document inside the webbrowser control 'Set field q with the value of Text1 'Submit the form (same result as click the search button) 'Wait until result are loaded MsgBox "Altavista search result loaded" |
Add the following code to a module:
Public Sub SetInputField(doc As HTMLDocument, Form As Integer, Name As String, Value As String) For q = 0 To doc.Forms(Form).length - 1 |
Additional useful subs:
Sub to get the contents from a textbox:
| Public Function GetInputField(doc As HTMLDocument, Form As Integer, Name As String) As String For q = 0 To doc.Forms(Form).Length - 1 If doc.Forms(Form)(q).Name = Name Then GetInputField = doc.Forms(From)(q).Value Exit For End If Next q End Function |
Sub to set a Checkbox:
| Public Sub SetCheckBox(doc As HTMLDocument, Form As Integer, Name As String, Value As Boolean) For q = 0 To doc.Forms(Form).Length - 1 If doc.Forms(Form)(q).Name = Name Then doc.Forms(From)(q).Checked = Value Exit For End If Next q End Sub |
Sub set a radio button:
| Public Sub SetRadioButton(doc As HTMLDocument, Form As Integer, Name As String, Name2 As String) For q = 0 To doc.Forms(Form).Length - 1 If (doc.Forms(Form)(q).Name = Name) And (doc.Forms(Form)(q).Value = Name2) Then doc.Forms(From)(q).Checked = True Exit For End If Next q End Sub |
Sub set a combo box:
| Public Function SetComboBoxValue(ByVal doc As IHTMLDocument3, Form As Integer, Name As String, Name2 As String) '**** This one bases it's selection on the Value of the - - Tag. Dim q, i For q = 0 To doc.Forms(Form).length - 1 If (doc.Forms(Form)(q).Name = Name) Then For i = 0 To doc.Forms(Form)(q).length - 1 If doc.Forms(Form)(q).Options(i).Value = Name2 Then doc.Forms(Form)(q).Options(i).Selected = True Exit For End If Next i End If Next q End Function |
Public Function SetComboValue(ByVal doc As IHTMLDocument3, Form As Integer, Name As String, Name2 As String) '**** This one bases it's selection on the Value of the Text after the - 'Text - Tag. Dim q, i For q = 0 To doc.Forms(Form).length - 1 If (doc.Forms(Form)(q).Name = Name) Then For i = 0 To doc.Forms(Form)(q).length - 1 If doc.Forms(Form)(q).Options(i).Text = Name2 Then doc.Forms(Form)(q).Options(i).Selected = True Exit For End If Next End If Next q |
0 reacties:
Een reactie plaatsen