如何将循环退出到另一个循环?

时间:2014-05-11 00:26:54

标签: vb.net

任何人都知道为什么我不能在" for"循环达到极限?
意图是循环旋转每个新单词
但是有些事情是非常错误的 ================================

Private Sub getWord()
        Static wordCount As Integer
        Dim txtLines As String()
        txtLines = TextBox1.Text.Split(CChar(vbCrLf))

        If (wordCount < txtLines.Count) Then
            WebBrowser1.Navigate("http://www.bing.com/search?q=" & txtLines(wordCount) & "&first=1&FORM=PERE")
            wordCount = wordCount + 1
        End If

    End Sub

    Dim i As Integer
    Dim max As Integer = 40

    Private Sub WebBrowser1_DocumentCompleted(sender As Object, e As WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
        If i >= max Then
            getWord()
        End If

        If (WebBrowser1.ReadyState = WebBrowserReadyState.Complete) Then

            For i As Integer = 1 To 40 Step 10
                WebBrowser1.Navigate("http://www.bing.com/search?q=" & txtLines(wordCount) & "&first=" & i & "&FORM=PERE")
            Next

            Dim PageElement As HtmlElementCollection = WebBrowser1.Document.GetElementsByTagName("a")
            Dim lk As String
            For Each lks As HtmlElement In PageElement
                lk = lks.GetAttribute("href")
                ListBox1.Items.Add(lk)
            Next
        End If
    End Sub            

1 个答案:

答案 0 :(得分:1)

我不完全确定我理解你的问题,但我会捅它。

如果您没有从循环中获得期望值,那么当您使用For i As Integer = 1 To 40 Step 10时,您只能获得1,11,21,31,但是您预计会有5个值?也许你需要这样做:

For i As Integer = 1 To 41 Step 10