QTP成长园地

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

上一篇 / 下一篇  2007-09-26 14:06:55 / 个人分类:QTP

今天写了一个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


TAG: QTP

 

评分:0

我来说两句

我的栏目

日历

« 2024-05-01  
   1234
567891011
12131415161718
19202122232425
262728293031 

数据统计

  • 访问量: 20312
  • 日志数: 14
  • 文件数: 1
  • 建立时间: 2007-09-19
  • 更新时间: 2014-04-11

RSS订阅

Open Toolbar