Wednesday 2 October 2013

Explain setCurrentRow method in QTP

In QTP, we have a datatable that can be used to store the runtime data from application or test data.
In datatable we have multiple sheets as mentioned below.
  1. GlobalSheet - can be accessed from any action.
  2. LocalSheet per Action - can be accessed from specific sheet only.
  3. Any user defined sheet. 
To add data into any sheet, you have to first get access to the sheet
By default globalsheet is refered.

To get reference to the any other sheet use below syntax
datatable.GetSheet("sheetname")

Examples of Datatable in QTP - 

'to add new sheet to datatable, you can use below method
datatable.AddSheet("sagar")


'to add parameter to the sheet
datatable.GetSheet("sagar").addParameter "id",1
'in above statement, we have added parameter with name id to sheet called sagar. 1 is the value added into first row of that parameter

'to set the row pointer we can use setCurrentRow method
datatable.GetSheet("sagar").setCurrentRow(1)
'Above statement will set row pointer to first row in sheet name sagar.

'to access data from the sheet, use below statement.
datatable("id","sagar") = "ppp:"
'above code will store ppp: in the sagar-sheet and under id column/parameter

'to move to next row, use below method.
'datatable.GetSheet("sagar").SetNextRow
datatable.GetSheet("sagar").setCurrentRow(2)
datatable("id","sagar") = "1"

'datatable.GetSheet("sagar").SetNextRow
'Please remember that You can only set a next  row that contains at least one value.
datatable.GetSheet("sagar").setCurrentRow(3)
datatable("id","sagar") = "112"

datatable.GetSheet("sagar").setCurrentRow(1)



for i=1 to 3
msgbox datatable("id","sagar")
datatable.GetSheet("sagar").SetNextRow
next

'to get the total number of rows in any sheet we can use.
datatable.GetSheet("sagar").getRowCount


You may find below links very useful if you want to know more about data tables in QTP.
  1. How to export datatable sheets to excel
  2. How to import excel-sheet to datatable
  3. How to read value from cell in datatable in QTP
  4. Explain setcurrentrow method in qtp
  5. Datatable object in qtp
  6. How to export datatable to excel in qtp
  7. How to get current sheet from datatable
  8. How to check if parameter exists in sheet in datatable in qtp
  9. Explain dtsheet object in qtp
  10. What are the utility objects in qtp


Please give your inputs, suggestions, feedback to Us about above QTP topic. We value your thoughts.

No comments:

Post a Comment

Please Leave your reply. We value your feedback and inputs

Best QTP Books

Everything About QTP

Hello Friends,
You can find QTP study material, Multiple choice questions (mcq), QTP question bank, QTP question papers, QTP notes, QTP questionnaire, scenario based QTP interview questions, QTP tutorial and QTP training on this site.

If you are a fresher or experienced QTP professional with (1/2/3/4) years of experience, this blog is just for you.