Solved

HTML object library/ WebBrowser object

Posted on 2001-06-14
4
272 Views
Last Modified: 2012-06-21
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(htmlDocument 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.getElementsByTagName
???
Next oElement
End If

For i = 1 To htmlDocument.Frames.length
     ? = GetHTMLelement(htmlDocument.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.
0
Comment
Question by:vt45
  • 2
4 Comments
 
LVL 28

Expert Comment

by:AzraSound
ID: 6190889
try this:

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
0
 

Author Comment

by:vt45
ID: 6192583
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(htmlDocument 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.getElementsByTagName
???
Next oElement
End If

For i = 1 To htmlDocument.Frames.length
    ? Set GetHTMLelement = GetHTMLelement(htmlDocument.Frames(i).Document, "string", "string2") 'i get a type mismatch here
next i

End function
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 6193027
try:
GetHTMLElement(htmlDocument.Frames.Item(i).Document, "string", "string2")
0
 
LVL 9

Accepted Solution

by:
kprestage earned 100 total points
ID: 6193636
Try this...


Public Static Function GetHTMLElements(htmlDocument As Object, Optional sElementTagName As String, Optional sElementAttribute As String, Optional sElementName As String, Optional NewCall As Boolean = True) As Collection
Dim oElement As HTMLHtmlElement
Dim i As Integer
Dim o As Object
Static x As Collection

If NewCall Then Set x = New Collection
Set GetHTMLElements = New Collection

If sElementTagName <> "" Then
    If sElementAttribute <> "" Then
        For Each oElement In htmlDocument.getElementsByTagName(sElementTagName)
            If UCase(oElement.Attributes(sElementAttribute)) = UCase(sElementName) Then
                x.Add oElement
            End If
        Next oElement
    Else
        For Each oElement In htmlDocument.getElementsByTagName(sElementTagName)
            x.Add oElement
        Next oElement
    End If
Else
    For Each oElement In htmlDocument.All
        x.Add oElement
    Next oElement
End If

If htmlDocument.frames.length > 0 Then
    For i = 0 To htmlDocument.frames.length - 1
        Set o = htmlDocument.frames(i).document
        GetHTMLElements o, sElementTagName, sElementAttribute, sElementName, False
    Next i
End If
Set GetHTMLElements = x

End Function

0

Featured Post

ScreenConnect 6.0 Free Trial

Check out the updates in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI that improves session organization and overall user experience. See the enhancements for yourself!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question