简体   繁体   English

遍历列表框项目

[英]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. 所以我想有一个包含8个项目的列表框,我想将列表框项目1输入到具有值datafield的html字段中,单击“发送”,然后导航回到我的网站“ mysite.com”,输入列表框项目2进入数据字段,单击发送并循环,直到输入所有列表框项。

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. 如果设置了文本框,则可以在文本框1中输入一行数据,但是如何循环遍历所有列表框项目。

   '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. 当我导航回到“ mysite.com”以等待加载的网站输入下一行数据时,还有什么好方法。 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. 就像在数据字段中输入列表框项目1一样,单击提交,导航回到主页,然后在数据字段中输入列表框项目2单击提交。 and do until its at the end of the listbox 并一直执行到列表框的末尾

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM