51Testing软件测试论坛

 找回密码
 (注-册)加入51Testing

QQ登录

只需一步,快速开始

微信登录,快人一步

查看: 1728|回复: 1
打印 上一主题 下一主题

[原创] DataTable 常用的方法

[复制链接]

该用户从未签到

跳转到指定楼层
1#
发表于 2010-3-31 16:48:40 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
'Methods of getting a Data Table value
val = datatable.Value("ParamName",dtGlobalSheet)
val = datatable.Value("ParamName","Global")

'by giving the sheet index starting from 1 for the global sheet
val = datatable.Value("ParamName",1)

'Sheet name or id is a optional parameter and is assumed to be as for global data sheet in case not provided
val = datatable.Value("ParamName")

'Value property is the default property of the DataTable object so DataTable("ParamName",dtGlobalSheet)
'is equivalent to datatable.Value("ParamName",dtGlobalSheet)
val = datatable("ParamName",dtGlobalSheet)
val = datatable("ParamName")

'Using the data table object model
val = datatable.GlobalSheet.DeleteParameter("ParamName").value
val = datatable.GlobalSheet.DeleteParameter("ParamName").valueByRow(1)

'============
'Various methods to get data table value
val = datatable.Value("ParamName",dtLocalSheet)
val = datatable.Value("ParamName","<LocalActionName>")
val = datatable("ParamName",dtLocalSheet)
val = datatable("ParamName","<LocalActionName>")

'The local sheet of the action which is executing this statement
val = datatable.LocalSheet.DeleteParameter("ParamName").value

'==============
'Function to check if DataTable exists
Function isSheetExists(sheetName)
   On error resume next
   isSheetExists = true
   err.clear
   Set objSheet = datatable.GetSheet(sheetName)
   If err.number <>0  Then
  isSheetExists= false
   End If
End Function

'==================
'This would be modified to 1.23456789E+010 due to autoformatting
datatable("ParamName") = "12345678901"
'This will not be auto formatted and will be treated as text
datatable("ParamName")= "'" &  "12345678901"

'==========
'Check if a parameter exists in data table
Function isParameterExists(sheetName,paramName)
On error resume next
isParameterExists = true
err.clear
parameTotal = datatable.GetSheet(sheetName).GetParameter(paramName)
   If err.number <>0  Then
  isParameterExists= false
   End If   
End Function

'===========
'Variable declaration
Dim i,j
Dim rowCount,colCount
Dim cellText,objTable

'Get table object
Set objTable = Browser("").Page("").WebTable("")

'Get the row count of the webtable
rowCount = objTable.RowCount

'Get the column count of the webtable
rowCount = objTable.ColumnCount(1)

'Create a output sheet
Set outSheet = datatable.AddSheet("Output")

'Greate Parameters based on the 1st row of the web table
For i=2 to colCount
cellText = objTable.GetCellData(1,i)

'Note in case the CellText contains space in between Then QTP will automatically convert it to a "_" character
outSheet.AddParameter celltext,""
Next

'Skip first row as we assumed it to be a header rows
For i = 2 to rowCount
outSheet.SetCurrentRow i-1

'Re-calculate the column count as some rows have different column sizes
colCount = objTable.ColumnCount(i)

For j = 2 to colCount
  cellText = objTable.GetCellData(i,j)
  outSheet.GetParameter(j-1).value = cellText
Next
Next

'===================
'Get a value by row
val = datatable.GetSheet("SheetName").GetParameter("ParamName").ValueByRow(RowNumber)

'==================
'Declare variable
Dim i,iCount

'Get the global sheet object
Set oGlobal  = datatable.GlobalSheet

'Get # of rows
iCount = oGlobal.GetRowCount

For i = 1 to iCount
'set the current row
oGolbal.SetCurrentRow i
'Execute the code to be repeated here
msgbox DataTable("UserName")
Next

'==================
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏
回复

使用道具 举报

该用户从未签到

2#
发表于 2010-4-8 11:51:01 | 只看该作者
AdvancedQTP.com上有一个在线测试QTP的DataTable的掌握程度的网页:
http://www.advancedqtp.com//wp-c ... z/DT/QuizForce.html
回复 支持 反对

使用道具 举报

本版积分规则

关闭

站长推荐上一条 /1 下一条

小黑屋|手机版|Archiver|51Testing软件测试网 ( 沪ICP备05003035号 关于我们

GMT+8, 2024-5-24 14:43 , Processed in 0.068264 second(s), 28 queries .

Powered by Discuz! X3.2

© 2001-2024 Comsenz Inc.

快速回复 返回顶部 返回列表