Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Get more than one getElementsByTagName in loop?

Posted on 2005-03-31
3
Medium Priority
?
1,053 Views
Last Modified: 2012-06-27
How do you obtain more than one TAG when recursing a document? What I am asking is how whould I extract a TABLE following the "A" link below? In other words, once I find a href link....move next extract the table following it so I can print both the link AND the first TABLE that follows after it!


Dim alink As HTMLLinkElement
Dim table As HTMLLinkElement
 
  For Each alink In WebBrowser1.Document.getElementsByTagName("A")
' just need to figure out how to get the table below the LINK!

debug.print alink
   
  Next
 
0
Comment
Question by:James
  • 2
3 Comments
 
LVL 28

Expert Comment

by:AzraSound
ID: 13676351
0
 

Author Comment

by:James
ID: 13677028
That sample wasn't any help.

How can I just check for a match in a loop to the elements? Like this:

Dim alink As HTMLLinkElement
Dim bfound as Boolean

  For Each alink In WebBrowser1.ALL

'Check if alink is a "A" tag then grab its text
' set a boolean to true if "A" has been found then
'next loop grab the "TABLE" text and set boolean = false and continue looking
'for the next "A" link

  Next

How difficult is it to make this work?

0
 
LVL 28

Accepted Solution

by:
AzraSound earned 1000 total points
ID: 13680989
Well you were asking about recursing a document, and that is exactly what that sample does.  Now that your question is more clear, we can proceed.  The only way to really do this is iterate over all elements in order, and flagging when you find your anchor element and then searching for your table.  Example:


Dim eleAny      As HTMLObjectElement
Dim doc         As HTMLDocument
Dim blnFound    As Boolean
Dim i           As Integer


Set doc = WebBrowser1.Document

For i = 0 To doc.All.length - 1
    Set eleAny = doc.All(i)
   
    If TypeName(eleAny) = "HTMLAnchorElement" Then
        blnFound = True
       
        Do Until blnFound = False Or i = doc.All.length
            i = i + 1
            Set eleAny = doc.All(i)
           
            If TypeName(eleAny) = "HTMLTable" Then
                'found the next table - process here
                blnFound = False
            End If
        Loop
    End If
Next
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…
Suggested Courses
Course of the Month13 days, 13 hours left to enroll

581 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