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 :wave:
Printable View
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 :wave:
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.
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
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. :wave:
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:
I have changed the values a bit! Hope it helps :wave: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
It would help :)
But is there any genuine dom based solution ? :)