当前位置:DOS资源站资料中心VBS脚本 → 在qtp中通过string 查找并定位列表页数和行数的VBS函数

在qtp中通过string 查找并定位列表页数和行数的VBS函数

减小字体 增大字体 作者:佚名  来源:本站整理  发布时间:2008-5-21 21:47:55

今天写了一个qtp中的VBS函数,功能:通过传入字符串来 查找并定位在table列表中的页数和行数的。

'-----------------------------------------------------------------
'function:Find pageNo, rowNo of a string in Table
'call method:define variable pageNo,rowNo in QTP before call this function
'Input parameter: obj_SelPage: SelectPage which is QTP WebList object
'                 obj_Table:   Table which is QTP WebTable object
'                 pageNo: Return index of page which string is located in list
'                          The first index in the list is numbered 0
'                 rowNo:   Return index of row which string is located
'                          The first index in the table is numbered 1
'                 strValue: A string which you will find in Table
'                 col:     the column of table where string will match with
'                          The first col in the table is numbered 1
'Return value:
'                  false : not find string in table
'                  true : find string in table
'For example in QTP:
'            ExecuteFile "..\..\Lib\Common.vbs"
'            Dim ipage,irow
'            value=FindStrInTab(obj_Select1,obj_Table1,ipage,irow,"jane",1)
'            If value=true then
'              msgbox ipage
'              msgbox irow
'           
'            End If         
'-----------------------------------------------------------------
Public Function FindStrInTab(obj_SelPage, obj_Table, byref pageNo,byref rowNo,strValue, col)
FindStrInTab=false
num= obj_SelPage.GetROProperty("items count")
For i =0 to num-1
     If obj_SelPage.Exist Then
       obj_SelPage.Select "#"&i
     End If
     If obj_Table.Exist Then
       tabNum=obj_Table.GetROProperty("rows")
     End If

     For j=2 to tabNum
       If trim(obj_Table.GetCellData(j, col))= trim(strValue) then
        pageNo=i
        rowNo=j
        FindStrInTab=true
       Exit For            
     End if
   Next
   If FindStrInTab=true Then
        Exit For
   End If
 Next
End Function