一个首页就有接近?20?个相同类别的控件(Link),虽然不多,但是一个个添加也够烦锁的,既然它们是完全相同类型的控件,那么使用描述性编程是一个上佳之选,下面来看这段脚本,看看是如何实现的:
Set baidu = Browser("micClass:=Browser").Page("micClass:=Page")
Print Baidu.Link("name:=新闻").Exist
With baidu
Print .Link("name:=贴吧").Exist
Print .Link("name:=知道").Exist
Print .Link("name:=MP3").Exist
Print .Link("name:=图片").Exist
Print .Link("name:=把百度设为主页").Exist
Print .Link("name:=搜索风云榜").Exist
Print .Link("name:=About Baidu").Exist
End With
Set baidu = Nothing
5. 从特定的文件中查询并返回Option Explicit
On Error Resume Next
Dim arrTxtArray()
Dim myFile
Dim SearchString
Dim objTextFile
Dim strNextLine
Dim intSize
Dim objFSO
Dim i
intSize = 0
myFile = "d:\search.txt"
SearchString = "error"
Const ForReading = 1
Set bjFSO = CreateObject("Scripting.FileSystemObject")
Set bjTextFile = objFSO.OpenTextFile(myFile, ForReading)
Do until objTextFile.AtEndOfStream
strNextLine = objTextFile.ReadLine
if InStr (strNextLine, SearchString)then
ReDim Preserve arrTxtArray(intSize)
arrTxtArray(intSize) = strNextLine
intSize = intSize + 1
End If
Loop
objTextFile.close
For i = LBound(arrTxtArray) To UBound(arrTxtArray)
WScript.Echo arrTxtArray(i)
Next
WScript.Echo("all done")
Note:
‘InStr([start,]string1,string2[,compare]) 返回起始位置
'ReDim Preserve actually performs two tasks. The first is to resize the array, and the second is to make sure you don’t lose any data when the array is resized.