QTP DataTable

 1.动态的在DataTable中添加新列并赋值

DataTable.Globa1Sheet.AddParameter "Column1","value1"

DataTable.Globa1Sheet.AddParameter "Column2","value2"

DataTable.Globa1Sheet.AddParameter "Column3","value3"

 

2.动态的在DataTable中添加新行并赋值

DataTable.GetSheet("Action1").SetCurrentRow(2)
DataTable.Value("Cloumn4","Action1")="Row2"

或者也可以是:DataTable("1","2") = "Row2"

 

 

3.动态获取DataTable中指定列的值

GetValue = DataTable("Cloumn5","Global")

Msgbox GetValue

GetValue1 = DataTable("Cloumn6","Action1")

Msgbox GetValue1

也可以这样:GetValue2 = DataTable("1","Action1")

Msgbox GetValue3

 

同样可以这样:循环读取Action的N列

For i= 1 To N

 Msgbox DataTable("i","Action1")

Next

 

如果有2个Aciton,Action1和Action2,要使它们在获取的时候保持行数一致,可以用下面2种方法:

①.可以直接定位Action2的行

DataTable.getSheet(Aciton2).SetCurrentRow(2)

②.使用变量传递保持行数一致

CurrentRow = DataTable.Sheet("Action1").GetCurrentRow

DataTable.Sheet("Action2").SetCurrentRow(CurrentRow)

 

4.动态获取DataTable中指定的值

getValueByRow = DataTable.Sheet("Action1").GetParameter("Column7").ValueByRow(2)

msgBox get ValueByRow

 

 

 

5.动态获取DataTable中当前行和设置当前行

①.获取当前行

CurrentRow = DataTable.Sheet("Action1").getCurrentRow

msgBox CurrentRow

 

②.设置当前行

DataTable.GetSheet("Action2").SetCurrentRow(5)

DataTable.GetSheet("Action2").AddParameter "Column8","value4"

CurrentRow2 = DataTable.GetSheet("Action2").GetCurrentRow

msgBox CurrentRow2

 

 

6.获取到DataTable总行数命令

AllRowcount = DataTable.GetSheet("Action1").GetRowCount

msgBox AllRowcount

posted @ 2013-11-26 13:28  Free-program  阅读(307)  评论(0)    收藏  举报