主题:莫名其妙的逻辑
一个webbrowser控件,一个Listbox,一个button,引用Microsoft Html object Library
代码如下
Private Sub Command1_Click()
Dim parentName As String
Dim keyword As String
parentName = "td"
keyword = "?ad="
Dim doc As HTMLDocument
Dim link As HTMLLinkElement
Set doc = Web.Document
For Each link In doc.links
Debug.Print link.toString
Debug.Print link.parentElement.tagName
Debug.Print UCase(link.parentElement.tagName) = UCase(parentName)
Debug.Print "instr(1," & link.toString & "," & keyword & ")=" & InStr(1, link.toString, keyword)
debug.print instr(1,link.tostring,keyword)<> 0
'如果链接的父标签的名字是td,[color=red]并且[/color]链接地址中有?ad=字样,就把地址添加到listBox。[color=blue]这样的逻辑应该是用And吧!!![/color]
If (UCase(link.parentElement.tagName) = UCase(parentnam)) [color=red]And[/color] (InStr(1, link.toString, keyword) <> 0) Then
'更怪异的是,把And 改为 or 之后,居然成功了。???!![em10]
List1.AddItem link.toString '这里总是不成功,即使if里的两个条件分别为True
End If
Next
End Sub
Private Sub Form_Load()
List1.AddItem "test string " '这里的addItem倒是成功了
Web.Navigate "http://www.ubux.us/surf.php"
End Sub
真不明白为何把And改为or之后就行了,这讲不通啊。
True And True =False!!! True or True = True 。
VB真TMD搞笑。
附debug的结果(部分)
http://www.ubux.us/index.php
DIV
False
instr(1,http://www.ubux.us/index.php,?ad=)=0
False
http://www.ubux.us/contact.php
DIV
False
instr(1,http://www.ubux.us/contact.php,?ad=)=0
False
[color=red]http://www.ubux.us/view.php?ad=54
TD
True
instr(1,http://www.ubux.us/view.php?ad=54,?ad=)=28[/color][color=blue]'照理说,这一项应该加到listBox里[/color][color=red]
True
http://www.ubux.us/view.php?ad=3
TD
True
instr(1,http://www.ubux.us/view.php?ad=3,?ad=)=28
True
http://www.ubux.us/view.php?ad=76
TD
True
instr(1,http://www.ubux.us/view.php?ad=76,?ad=)=28
True[/color]
http://www.ubux.us/archive.php
DIV
False
instr(1,http://www.ubux.us/archive.php,?ad=)=0
False
代码如下
Private Sub Command1_Click()
Dim parentName As String
Dim keyword As String
parentName = "td"
keyword = "?ad="
Dim doc As HTMLDocument
Dim link As HTMLLinkElement
Set doc = Web.Document
For Each link In doc.links
Debug.Print link.toString
Debug.Print link.parentElement.tagName
Debug.Print UCase(link.parentElement.tagName) = UCase(parentName)
Debug.Print "instr(1," & link.toString & "," & keyword & ")=" & InStr(1, link.toString, keyword)
debug.print instr(1,link.tostring,keyword)<> 0
'如果链接的父标签的名字是td,[color=red]并且[/color]链接地址中有?ad=字样,就把地址添加到listBox。[color=blue]这样的逻辑应该是用And吧!!![/color]
If (UCase(link.parentElement.tagName) = UCase(parentnam)) [color=red]And[/color] (InStr(1, link.toString, keyword) <> 0) Then
'更怪异的是,把And 改为 or 之后,居然成功了。???!![em10]
List1.AddItem link.toString '这里总是不成功,即使if里的两个条件分别为True
End If
Next
End Sub
Private Sub Form_Load()
List1.AddItem "test string " '这里的addItem倒是成功了
Web.Navigate "http://www.ubux.us/surf.php"
End Sub
真不明白为何把And改为or之后就行了,这讲不通啊。
True And True =False!!! True or True = True 。
VB真TMD搞笑。
附debug的结果(部分)
http://www.ubux.us/index.php
DIV
False
instr(1,http://www.ubux.us/index.php,?ad=)=0
False
http://www.ubux.us/contact.php
DIV
False
instr(1,http://www.ubux.us/contact.php,?ad=)=0
False
[color=red]http://www.ubux.us/view.php?ad=54
TD
True
instr(1,http://www.ubux.us/view.php?ad=54,?ad=)=28[/color][color=blue]'照理说,这一项应该加到listBox里[/color][color=red]
True
http://www.ubux.us/view.php?ad=3
TD
True
instr(1,http://www.ubux.us/view.php?ad=3,?ad=)=28
True
http://www.ubux.us/view.php?ad=76
TD
True
instr(1,http://www.ubux.us/view.php?ad=76,?ad=)=28
True[/color]
http://www.ubux.us/archive.php
DIV
False
instr(1,http://www.ubux.us/archive.php,?ad=)=0
False