Results 1 to 6 of 6

Thread: populating combo box options

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 2006
    Location
    Osaka
    Posts
    200

    populating combo box options

    from a webpage which has a combo box populated with options -- i want to populate combo box on form with same options.

    anybody please help

  2. #2
    PowerPoster gavio's Avatar
    Join Date
    Feb 2006
    Location
    GMT+1
    Posts
    4,462

    Re: populating combo box options

    If you're talking about "<option>" tag, then you can use this. Retrieve the source with Inet (MS Internet Transfer) and loop through the string with Shirazamod's function.

  3. #3
    PowerPoster lintz's Avatar
    Join Date
    Mar 2003
    Location
    The 19th Hole
    Posts
    2,697

    Re: populating combo box options

    Add the Inet control to your form then add this code to a command button.

    VB Code:
    1. Private Sub Command1_Click()
    2. Dim Source As String
    3. Dim pos As Long
    4.  
    5. 'get source of webpage
    6. Source = Inet1.OpenURL("http://www.yoursite.com/yourpage.html")
    7.  
    8. 'find where first <option> is
    9. pos = InStr(1, Source, "<option>")
    10.  
    11. Do Until pos = 0
    12.  
    13. Combo1.AddItem Mid$(Source, pos + 8, InStr(pos + 1, Source, "<") - (pos + 8))
    14.  
    15. 'find where next <option> is
    16. pos = InStr(pos + 1, Source, "<option>")
    17. Loop
    18.  
    19. End Sub

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Jan 2006
    Location
    Osaka
    Posts
    200

    Re: populating combo box options

    I think using dom or html library would be best to retrieve data.

    Because i require two values

    code:
    <option value="2">Java</option>

    I want to get value
    2 and Java

    means value variable and text.

    Thank You.

  5. #5
    PowerPoster gavio's Avatar
    Join Date
    Feb 2006
    Location
    GMT+1
    Posts
    4,462

    Re: populating combo box options

    Here's an example (let's say you already retrieved the source and saved it into the "source" string) - also, Chr(34) is a substitution for the " sign:
    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Form_Load()
    4.     Dim source As String
    5.         source = "<option value=" & Chr(34) & "15000" & _
    6.                  Chr(34) & ">This is only a test!</option>"
    7.  
    8.     Dim tmpPos As Long, tmpPos2 As Long
    9.     Dim values(1 To 2) As String
    10.  
    11.         If InStr(1, source, LCase("<option value=")) > 0 Then
    12.             tmpPos = InStr(1, source, LCase("<option value=")) + Len("<option value=")
    13.             tmpPos2 = InStr(tmpPos, source, ">")
    14.             values(1) = Mid(source, tmpPos, tmpPos2 - tmpPos)
    15.             values(1) = Replace(values(1), Chr(34), "")
    16.             tmpPos = tmpPos2 + 1
    17.             tmpPos2 = InStr(tmpPos2, source, LCase("</option"))
    18.             values(2) = Mid(source, tmpPos, tmpPos2 - tmpPos)
    19.                 Debug.Print Join(values, vbCrLf)
    20.         End If
    21. End Sub
    I have changed the values a bit! Hope it helps

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Jan 2006
    Location
    Osaka
    Posts
    200

    Re: populating combo box options

    It would help

    But is there any genuine dom based solution ?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width