For Loop problem in QTP

I am using the For Loop to get data from the data table. The summary code is:
C=datatable.getrowcount
For i=1 to c
msgbox Datatable.Value("Column1")
Next
'The message box always returns data of row 1. Irrespective of the iteration. How is it possible.

Questions by raj2k0072000

Showing Answers 1 - 22 of 22 Answers

Here you are not changing the row number that's why each and every time its fetching data from first row which the default row

I hope the following code would help? you
I am using the For Loop to get data from the data table. The summary code is:
C=datatable.getrowcount
For i=1 to c
datatable.setcurrentrow(i)
msgbox Datatable.Value("Column1")
Next


Raghuram Gupta
9866379523

  Was this answer useful?  Yes

ankitjain082@gmail.com

  • Aug 29th, 2011
 

Use this

RowCount=DataTable.GetSheet("Global").GetRowCount
For i =1 to RowCount

Data

DataTable.GetSheet("Global").SetNextRow
Next
Window("Flight Reservation").Close

  Was this answer useful?  Yes

Divya

  • Sep 9th, 2011
 

Hi I hope this will useful to u

Code
  1. c=datatable.getrowcount

  2. for i=1 to c

  3. datatable.setcurrentrow(i)

  4. msgbox datatable.value("column1")

  5. next


  Was this answer useful?  Yes

dhanunjay

  • Aug 29th, 2012
 

iRows=DataTable.getrowcount
For i=1 to iRows
DataTable.SetCurrentRow(i)
MsgBox DataTable("Test", dtGlobalSheet)
DataTable.SetNextRow
Next

RameshTulal

  • Aug 14th, 2013
 

Hi All..

I have followed the discussion above but in my machine, the code is executing rcountno*rowcount times

I mean to say my rcount is "5" and yes my script is executing 5*5 time.(seems like script is a parent loop for my FOR loop)
Any body please tell me whts wrong i am doing

Thanks in Advance
Ramesh

  Was this answer useful?  Yes

NKANAP

  • Sep 17th, 2013
 

RC=datatable.GetRowCount
For i=1 to RC
datatable.SetCurrentRow(i)

( NO NEED TO WRITE DATATABLE.Setcurrentrow IN THE SCRIPT)

Next

  Was this answer useful?  Yes

helloqtp

  • Jul 5th, 2014
 

I think the issue lies in the settings , where you have to check for one iteration only .. by default it remains checked as for all the rows ..

  Was this answer useful?  Yes

rohan

  • May 22nd, 2015
 

rc = datatable.getsheet("sheetname").getRowCount
to increase the loop
for i = 1 to rc
datatable.SetCurrentRow(i)
obj1 = datatable.value("Columnname","sheetname")
next

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions