Link to home
Start Free TrialLog in
Avatar of Preece
PreeceFlag for United States of America

asked on

WebBrowser and parsing select list

I am using VB 6 and the MSHTML Object Lib.  So, I have a WebBrowser object bolted into a VB form, I can browse to a site, but I need to know how to parse some info:

-  I have a select list (like a listbox in VB!) filled with a list of items, and I would like to be able to loop thru each item in the list.  When I get a match on what particular item i am looking for, then I would like to set the index and show it as selected.  Just like I can easily do in VB!  Here is an example of the select object:

<select name="numlist" size=7>
<OPTION VALUE="ONE" SELECTED>1 . ONE
<OPTION VALUE="TWO">2 . TWO
<OPTION VALUE="THREE">3 . THREE
<OPTION VALUE="FOUR">4 . FOUR
<OPTION VALUE="FIVE">5 . FIVE
</select>

Thanks in advance,
Preece
Avatar of Ark
Ark
Flag of Russian Federation image

Try
WebBrowser1.Document.All("numlist").slectedindex=3

Regards
Ark
Avatar of Preece

ASKER

I'll try that...but also, I would like to know how to loop thru the "numlist"...

Thanks,
Preece
For i=1 to 5
   Debug.Print WebBrowser1.Document.All("numlist")(i)
Netx i

Regards
Ark
Avatar of Preece

ASKER

ok...the REAL trick is when you don't  know the length of the list....
that is what i am getting at...something like:

for i = 0 to numlist.listcount
    debug.print blah blah blah
next i

Thanks again,
Preece
Avatar of Preece

ASKER

ok...the REAL trick is when you don't  know the length of the list....
that is what i am getting at...something like:

for i = 0 to numlist.listcount
    debug.print blah blah blah
next i

Thanks again,
Preece
Avatar of Preece

ASKER

Does anyone know how to accomplish this?

Might it be something like:

For i=1 to WebBrowser1.Document.All("numlist").length
  Debug.Print WebBrowser1.Document.All("numlist")(i)
Netx i



Dim cb As HTMLSelectElement


Private Sub WB1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
If (pDisp Is WB1.Object) Then
    Dim i As Integer
    Set cb = WB1.Document.All("numlist")
    For i = 0 To cb.length - 1
        Debug.Print cb.Item(i).Value
    Next i
End If
End Sub
Avatar of Preece

ASKER

Thanks again for your help Richie!  I tried your suggestion, but it yields strange results!

        Dim cboBox as object
        Set cboBox = WebBrowser1.Document.All("numlist")
        For lX = 0 To cboBox.length - 1
            MsgBox cboBox.Item(lX).value
        Next lX

It is only finding a length of 2.  When the first item in the list is selected, the two msgboxes show "ONE" and "ONE".  

When another item is selected, say "FOUR", then the msgboxes show "ONE" and then "FOUR".  It is only finding the option value for the first in the list and then the selected item.

Thanks again!
Preece
Avatar of Preece

ASKER

Darn!  I thought that I caught an error and had it!  With the previous msg, I was dimming cboBox as an Object, and was getting the results that I posted.  Then, I finally saw the "Dim cb As HTMLSelectElement" in your post.  So, I dimmed the cboBox as As HTMLSelectElement, and now on this line of code:

Set cboBox = WebBrowser1.Document.All("numlist")

I get an error 13 "Type mismatch"!

Things that make you go "hmmmmmmmm......"
well, i did try the code before post it and never get an error on it, trust me!
That code only prints ALL items. If you need which is selected just change to:

Dim cboBox as HTMLSelectElement
       Set cboBox = WebBrowser1.Document.All("numlist")
       For lX = 0 To cboBox.length - 1
           if cbobox.item(IX).selected then
               MsgBox cboBox.Item(lX).value
               exit for
           end if
       Next lX
Avatar of Preece

ASKER

Thanks again Richie!  What I am trying to accomplish is this:  

I want to control an embedded browser, select a particular item in the list, then click the submit button.  I am doing all of this but selecting the item in the list...

To compound the problem, I just discovered that the friggin page has two lists with the same name!  Oh, what a headache!  One has a size of 1, the other a size of 7.  I am trying to select items from the one that has the size of 7.  

Any suggestions?  
well, this is not so good, but we could count them and act after that.
could you post the target url here?
Avatar of Preece

ASKER

http://www.oanda.com/convert/classic

As you can see, there are two lists at the top right.  These are short lists and I won't use them.  But they are named the same as the two long lists in the middle of the page.  So, for instance, I would like to, programmatically, select Argentine Peso and Australian Dollar, then click the "Convert Now" button.  The resulting page I will collect data from.  And that's it!

Sorry for taking so long, as I am working on multiple projects at once!

Thanks,
Preece
Avatar of Preece

ASKER

I've increased the points to 100!
i am almost there, do you know the name for select control of that page? (sorry, i am very busy just right know)
ASKER CERTIFIED SOLUTION
Avatar of Richie_Simonetti
Richie_Simonetti
Flag of Argentina image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Preece

ASKER

Thanks Richie!  With a little modification, this is working great!  

Preece
OK. That's code just show you how to access items in list boxes.
Thanks for "A" grade.