'打开预检测的WebTable所在页面
Browser...
'快速排序:ReArr 是待排序数组, head和tail是该数组的最小下标和最大下标
Public Function QSort(ByRef ReArr, ByVal head, ByVal tail)
Dim lef, rig
Dim pivot
If head < tail Then
lef=head
rig=tail
pivot=ReArr(lef)
While (lef <> rig)
'strcmop(string,string,1) 1:代表按照汉字比较; 默认0:代表按照二进制比较
While (lef < rig and strcomp(ReArr(rig),pivot,1) > 0)
rig = rig-1
Wend
If lef <rig Then
ReArr(lef) = ReArr(rig)
lef = lef+1
End If
While (lef < rig and strcomp(ReArr(lef),pivot,1) < 0)
lef = lef+1
Wend
If lef <rig Then
ReArr(rig) = ReArr(lef)
rig = rig-1
End If
Wend
ReArr(lef) = pivot
call QSort(ReArr, head, lef-1)
call QSort(ReArr, lef+1, tail)
End If
End Function
'两数组比较
Public function ArrCmp(arr1,arr2,Rows1,Rows2)
If Rows1 <> Rows2 Then
Msgbox "WebTable与数据库记录数不一致!"
exit function
End If
For i = 0 to Rows1
If strcomp(arr1(i),arr2(i),1) <> 0 Then
msgbox "第" & i & "行记录不一致,请查看!"
Exit for
exit function
End If
Next
msgbox "成功!"
End Function
'初始化webtable信息,为遍历WebTable所有记录做准备(WebTable格式:第1行:标题,中间:记录,最后1行:页码行)
Dim tWebTable
Dim intWTRows
Dim intWTCols
Dim intWTPages
set tWebTable=Browser("...").Page("...").Frame("main").WebTable("grd...")
intWTRows=tWebTable.GetRoProperty("rows")
intWTCols=tWebTable.GetRoProperty("cols")
intWTPages=tWebTable.ChildItemCount(intWTRows,1,"Link") + 1
Dim arrWT()
Call TraverseWT(tWebTable,intWTRows,intWTCols,intWTPages)
'使用getcelldata(i,j)的方法遍历webtable把表格内容存入一个数组中,将每条记录拼成一个字符串,构成一个一维数组
Public function TraverseWT(WebTable,byref WTRows,WTCols,WTPages)
Dim intAllRows
Dim intCurRows
intAllRows = 0
For k=1 to WTPages
If WebTable.Exist Then
intCurRows = WebTable.GetRoProperty("rows")-2
intAllRows = intAllRows + intCurRows
WTRows = intAllRows
End If
For i=2 to intCurRows+1
Dim strData1
strData1=""
For j=2 to WTCols-2
ReDim preserve arrWT(intAllRows-1)
strData1 = strData1 & WebTable.GetCellData(i,j) & "&"
arrWT(intAllRows - intCurRows + i-2) = strData1
Next
Next
If k< WTPages Then
WebTable.ChildItem(intCurRows+2,1,"Link",k-1).click
set WebTable=Browser("配电网管理系统_2").Page("配电网管理系统").Frame("main").WebTable("grd...")
End If
Next
'调用排序函数
Call QSort(arrWT,0,intWTRows-3)
End Function
'使用数据库连接组件ADODB连接后台数据库,使用数据结果集对象保存select查询结果,将每条记录拼成一个字符串,构成一个一维
数组
Dim Cnn
Dim Rst
Dim strCnn
Dim strSql
strCnn="Provider=OraOLEDB.Oracle.1;Password=fm;Persist Security Info=True;User ID=fm;Data Source=pms04"
Set Cnn=CreateObject("ADODB.Connection")
Cnn.Open strCnn
Set Rst=CreateObject("ADODB.Recordset")
'sql查询语句
strSql="SELECT a.f_... || '&' || a.f_.... as f_String FROM vw_... ORDER BY a.f_...,a.f_..."
Rst.open strSql,Cnn,1,3
'Rst.movelast '光标到最后一行
Dim iRow
iRow = Rst.recordcount-1
msgbox (iRow)
i=1
Dim arrDB()
While not Rst.eof
Dim strData2
strData2 = Rst("f_String")
Dim num
reDim preserve arrDB(iRow)
arrDB(i-1) = strData2
i=i+1
Rst.movenext '光标到下一行
Wend
Dim intDBRows
intDBRows = i-2
'调用排序函数
Call QSort(arrDB,0,intDBRows)
'调用两数组比较函数
Call ArrCmp(arrWT,arrDB,intWTRows-1,intDBRows)