我是stackoverflow.com的新手,所以如果问题不是很聪明人们向所有人道歉。
有人能告诉我当计数器达到“max = 100”时如何停止?
Dim i As Integer
Dim max As Integer
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
i = 10
max = 100
WebBrowser1.Navigate("http://www.bing.com/search?q=a&first=" & i & "&FORM=PERE")
i += 9
End Sub
Private Sub WebBrowser1_DocumentCompleted(sender As Object, e As WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
Timer1.Enabled = True
If i >= max Then
Exit Sub
End If
If (WebBrowser1.ReadyState = WebBrowserReadyState.Complete) Then
WebBrowser1.Navigate("http://www.bing.com/search?q=a&first=" & i & "&FORM=PERE")
i += 9
End If
End Sub
我在DocumentoCompleted事件中添加了“WebBrowser1_DocumentCompleted”
在浏览器状态下运行的循环
问题是:如果达到极限“max”,我怎么能阻止它?
答案 0 :(得分:0)
您可以使用if语句:
i += 9
If (i >= MAX) Then
i = MAX
Button1.Enabled = False
End if
它简单,做你想要的。由于您只需单击即可运行代码,因此只需禁用该按钮即可。但是,当您的代码被写入时,每次单击按钮时,i
看起来都会重置为10.