by Stephen B. Gauntt (1 Submission)
Category: VB function enhancement
Compatability: Visual Basic 3.0
Difficulty: Intermediate
Date Added: Wed 3rd February 2021
Rating: (2 Votes)
Allows you to retrieve values from fields (i.e. hidden fields) in a web page loaded using the WebBrowser control. Very simple function, but I've found it extremely useful. Please don't forget to leave a comment to let me know what you think!
To call this function try this example:
MyValue = GetWebValue(MyWebBrowser,"fieldname")
Will return the value or nothing if not found.
Function GetWebValue(WebBrowser As WebBrowser, value As String)
'Checking if a Frame Page is being displayed
On Error GoTo EndStuff:
Set LkpWeb = WebBrowser.Document
If LkpWeb.Frames.Length > 0 Then
'Cycle through the frames
For i = 0 To LkpWeb.Frames.Length - 1
Set Lkp = LkpWeb.Frames(i).Document.All
On Error Resume Next
GetWebValue = Lkp.Item(CStr(value)).value
If Err.Number = 0 Then
Exit For
End If
DoEvents
Next
Else
Set LkpWeb = WebBrowser.Document.All
On Error Resume Next
GetWebValue = LkpWeb.Item(CStr(value)).value
End If
EndStuff:
End Function