Solved

HTML object library/ WebBrowser object

Posted on 2001-06-14
4
275 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

763 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