Dustin Bobbitt
Dustin Bobbitt

Reputation: 25

Loop through listbox items

I am making a program to automate entering data into a website im building. I can only enter one line of data at a time. So I want to have a listbox with say 8 items, I want to take listbox item 1 enter it into an html feild with the value datafield, click send, then navigate back to my site "mysite.com", enter listbox item 2 into datafield, click send and loop until all listbox items have been entered.

If I set a textbox, this works to enter a single line a data from textbox 1, but how could I loop it to go go through all my listbox items.

   'Paste url  from textbox to datafield
        WebBrowser1.Document.GetElementById("datafield").SetAttribute("value", textbox1.text)

        'click search button
        Dim allelements As HtmlElementCollection = WebBrowser1.Document.All

        For Each webpageelement As HtmlElement In allelements

            If webpageelement.GetAttribute("type") = "submit" Then

                webpageelement.InvokeMember("click")

            End If

Also is there any good way for when I navigate back to "mysite.com" to wait until the sites loaded to enter the next line of data. If there anyway you could, please take the code I posted and show me a way to paste data from the listbox to the datafield. Like enter listbox item 1 to datafield, click submit, navigate back to homepage then enter listbox item 2 in datafield click submit. and do until its at the end of the listbox

Upvotes: 0

Views: 19420

Answers (1)

Drarig29
Drarig29

Reputation: 2245

Use this :

For Each item In ListBox1.Items
    'Do stuff
    MsgBox(item.ToString)
Next

Or if you need the index of each item, use this :

For i = 0 To ListBox1.Items.Count - 1
    'Do stuff
    MsgBox(ListBox1.Items(i).ToString)
Next

Upvotes: 4

Related Questions