vt45
asked on
HTML object library/ WebBrowser object
I'm writing a function to scan through an HTML document object, and find an element based on the arguments being passed in.
Public Function GetHTMLElement(htmlDocumen t as HTMLDocument, sElementName as String, Optional sElementType as String)
Dim oElement as HTMLhtmlElement
Dim i as Integer
If sElementType <> "" then
For Each oElement in htmlDocument.getElementsBy TagName
???
Next oElement
End If
For i = 1 To htmlDocument.Frames.length
? = GetHTMLelement(htmlDocumen t.Frames(i ).Document , "string", "string2")
next i
End function
This is all I have so far. I'm interested in returning a collection of elements that match arg2 and arg3. How do I populate this function with each element that matches the criteria? Thanks for any commets/suggestions.
Public Function GetHTMLElement(htmlDocumen
Dim oElement as HTMLhtmlElement
Dim i as Integer
If sElementType <> "" then
For Each oElement in htmlDocument.getElementsBy
???
Next oElement
End If
For i = 1 To htmlDocument.Frames.length
? = GetHTMLelement(htmlDocumen
next i
End function
This is all I have so far. I'm interested in returning a collection of elements that match arg2 and arg3. How do I populate this function with each element that matches the criteria? Thanks for any commets/suggestions.
ASKER
Azra-
That works for one document, but if a particular webpage contains x frames, that means x document objects. I want this function to keep calling itself until it has looped through all subframes and at the same time populating the collection the function is defined as.
Public Function GetHTMLElement(htmlDocumen t as HTMLDocument, sElementName as String, Optional sElementType
as String) as Collection
Dim oElement as HTMLhtmlElement
Dim i as Integer
If sElementType <> "" then
For Each oElement in htmlDocument.getElementsBy TagName
???
Next oElement
End If
For i = 1 To htmlDocument.Frames.length
? Set GetHTMLelement = GetHTMLelement(htmlDocumen t.Frames(i ).Document , "string", "string2") 'i get a type mismatch here
next i
End function
That works for one document, but if a particular webpage contains x frames, that means x document objects. I want this function to keep calling itself until it has looped through all subframes and at the same time populating the collection the function is defined as.
Public Function GetHTMLElement(htmlDocumen
as String) as Collection
Dim oElement as HTMLhtmlElement
Dim i as Integer
If sElementType <> "" then
For Each oElement in htmlDocument.getElementsBy
???
Next oElement
End If
For i = 1 To htmlDocument.Frames.length
? Set GetHTMLelement = GetHTMLelement(htmlDocumen
next i
End function
try:
GetHTMLElement(htmlDocumen t.Frames.I tem(i).Doc ument, "string", "string2")
GetHTMLElement(htmlDocumen
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
On Error Resume Next
Dim oCollection As New Collection
For Each oElement In htmlDocument
If Ucase$(oElement.name) = UCase$(sElementName) Then
If UCase$(oElement.type) = UCase$(sElementType) Then
oCollection.Add oElement
End If
End If
Next