VB循环问题 [英] VB looping issue
问题描述
您好,VB大师的
多次陷入与编程循环相关的问题.
RUnning into an issue related to the programing looping more than once.
私人
Sub AxWebBrowser1_DocumentComplete( ByVal 发件人 As 系统. 对象 , ByVal e As DWebBrowserEvents2_DocumentCompleteEvent ) 手柄 AxWebBrowser1.DocumentComplete
Sub AxWebBrowser1_DocumentComplete(ByVal sender As System.Object, ByVal e As AxSHDocVw.DWebBrowserEvents2_DocumentCompleteEvent) Handles AxWebBrowser1.DocumentComplete
Dim As 整数
Dim a As Integer
Dim b As 字符串
Dim b As String
如果 AxWebBrowser1.Document.Links.length> 0 然后
If AxWebBrowser1.Document.Links.length > 0 Then
对于 a = 1 收件人 AxWebBrowser1.Document.Links.length-1
For a = 1 To AxWebBrowser1.Document.Links.length - 1
b = b& AxWebBrowser1.Document.Links(a).InnerHtml& vbCrLf
b = b & AxWebBrowser1.Document.Links(a).InnerHtml & vbCrLf
下一个
TextBox2.Text = b
TextBox2.Text = b
结束 如果
End If
synthesizer.SpeakAsync(
synthesizer.SpeakAsync(
欢迎使用 & AxWebBrowser1.Document.nameprop.ToString)
"Welcome to " & AxWebBrowser1.Document.nameprop.ToString)
结束 Sub
End Sub
私有 Sub InsertDOMNodes( ByVal parentnode As IHTMLDOMNode , ByVal tree_node As TreeNode )
Private Sub InsertDOMNodes(ByVal parentnode As IHTMLDOMNode, ByVal tree_node As TreeNode)
如果 parentnode.hasChildNodes() 然后
If parentnode.hasChildNodes() Then
Dim allchild As IHTMLDOMChildrenCollection = CType (parentnode.childNodes, IHTMLDOMChildrenCollection )
Dim allchild As IHTMLDOMChildrenCollection = CType(parentnode.childNodes, IHTMLDOMChildrenCollection)
Dim 长度 As 整数 = allchild.length
Dim length As Integer = allchild.length
Dim 我 As 整数 = 0
Dim i As Integer = 0
做 而 我<长度
Do While i < length
Dim child_node As IHTMLDOMNode = CType (allchild.item(i), IHTMLDOMNode )
Dim child_node As IHTMLDOMNode = CType(allchild.item(i), IHTMLDOMNode)
Dim tempz As TreeNode = tree_node
Dim tempz As TreeNode = tree_node
InsertDOMNodes(child_node,tempz)
InsertDOMNodes(child_node, tempz)
'调用递归Sub
i = i + 1
i = i + 1
环路
结束 如果
End If
结束 Sub
End Sub
此系统两次执行了这行代码 "
This system is executing this line of code twice "
synthesizer.SpeakAsync(
synthesizer.SpeakAsync(
欢迎使用 & AxWebBrowser1.Document.nameprop.ToString);
"Welcome to " & AxWebBrowser1.Document.nameprop.ToString)"
如何阻止这种情况的发生.任何帮助将不胜感激.
提前感谢.
此致
SAPKING.
推荐答案
您知道那行代码执行了两次,而不是该DocumentComplete事件触发两次?您应该在文档完成事件处理程序的开头放置一个断点,并逐行跟踪代码
可以看到它所在的位置,但是上面的代码并没有理由在子调用的每次调用中,您所引用的行都应该执行多次. Do you know that it is that line of code executing twice, rather than the DocumentComplete event firing twice? You should put a breakpoint at the start of the document complete event handler, and trace the code through line by line
to see which it is, but there's no reason from the above code that the line you refer to should execute more than once within each invocation of the sub. 这篇关于VB循环问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!