|
-
Oct 19th, 2006, 06:52 AM
#1
Thread Starter
Addicted Member
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
-
Oct 19th, 2006, 07:23 AM
#2
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.
-
Oct 19th, 2006, 07:23 AM
#3
Re: populating combo box options
Add the Inet control to your form then add this code to a command button.
VB Code:
Private Sub Command1_Click()
Dim Source As String
Dim pos As Long
'get source of webpage
Source = Inet1.OpenURL("http://www.yoursite.com/yourpage.html")
'find where first <option> is
pos = InStr(1, Source, "<option>")
Do Until pos = 0
Combo1.AddItem Mid$(Source, pos + 8, InStr(pos + 1, Source, "<") - (pos + 8))
'find where next <option> is
pos = InStr(pos + 1, Source, "<option>")
Loop
End Sub
-
Nov 9th, 2006, 01:40 AM
#4
Thread Starter
Addicted Member
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.
-
Nov 9th, 2006, 02:18 AM
#5
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:
Option Explicit
Private Sub Form_Load()
Dim source As String
source = "<option value=" & Chr(34) & "15000" & _
Chr(34) & ">This is only a test!</option>"
Dim tmpPos As Long, tmpPos2 As Long
Dim values(1 To 2) As String
If InStr(1, source, LCase("<option value=")) > 0 Then
tmpPos = InStr(1, source, LCase("<option value=")) + Len("<option value=")
tmpPos2 = InStr(tmpPos, source, ">")
values(1) = Mid(source, tmpPos, tmpPos2 - tmpPos)
values(1) = Replace(values(1), Chr(34), "")
tmpPos = tmpPos2 + 1
tmpPos2 = InStr(tmpPos2, source, LCase("</option"))
values(2) = Mid(source, tmpPos, tmpPos2 - tmpPos)
Debug.Print Join(values, vbCrLf)
End If
End Sub
I have changed the values a bit! Hope it helps
-
Nov 9th, 2006, 03:00 AM
#6
Thread Starter
Addicted Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|