Micro Focus QTP (UFT) Forums
For Loop - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: UFT / QTP Beginners (https://www.learnqtp.com/forums/Forum-UFT-QTP-Beginners)
+--- Thread: For Loop (/Thread-For-Loop)



For Loop - munisw - 06-24-2011

I am a QTP beginer, and trying to learn in with a real project. My programming skills are not upto the par.

here is the problem.

have a dialog with three fileds that i am working on

Customer Name, customer TIN, customer TTN number, First two are required. "Customer Button".

First need to enter the data in the fields and hit Add Customer, another set of three fileds open user will enter the differetn entry for a different customer.

I have global sheet of 99 customer names and TIN, but the loop is keep defaulting to the first customer. It appears that cusomer fields is customer(0), cutomer(1) and so on, it seems it is an array.

Need to know how do i loop 99 times and enter in the new custoemr filed every time hit add custoemr button.

My current code is

Code:
Dim i,  customer_name

For i= 1 to 2
Browser("Login").Page("UAR").WebEdit("customers[0].name").Set DataTable("Customer_name", dtGlobalSheet)
Browser("Login").Page("UAR").WebEdit("customers[0].taxIdNumberRaw").Set DataTable("TIN_Number", dtGlobalSheet)
Browser("Login").Page("UAR").WebButton("Add Customer").Click
Next



RE: For Loop - Skepsis - 06-28-2011

You need to add a line in the loop that moves the 'pointer to the data table row' on one row. It is not automatic so will continue to get the same row each loop.


RE: For Loop - tarun - 06-28-2011

Use Datatable.setcurrentrow(i) in your for loop


RE: For Loop - rajpes - 07-05-2011

Two ways of doing it
1. remove that for loop and set "run on all rows" option

2.set "run one iteration only" option


Code:
For i= 1 to 99

'you missed this line
[b]Datatable.setcurrentrow i[/b]

Browser("Login").Page("UAR").WebEdit("customers[0].name").Set DataTable("Customer_name", dtGlobalSheet)
Browser("Login").Page("UAR").WebEdit("customers[0].taxIdNumberRaw").Set DataTable("TIN_Number", dtGlobalSheet)
Browser("Login").Page("UAR").WebButton("Add Customer").Click
Next