Micro Focus QTP (UFT) Forums
Want to Iterate!! - 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: VB Scripting/Descriptive Programming (https://www.learnqtp.com/forums/Forum-VB-Scripting-Descriptive-Programming)
+--- Thread: Want to Iterate!! (/Thread-Want-to-Iterate)



Want to Iterate!! - wannalearn_qtp - 12-30-2009

Hi All,

Greetings of the day.
My Problem is , i have my application here.
So basically my module is to create a user.
So when we click on the "add user" button , it will give me around 15-20 text boxes, combo boxes and check boxes to fill out.

here is a piece of code...
-----------------------------------------------------------
Code:
set sh = CreateObject("Scripting.FileSystemObject")
set exl = CreateObject("Excel.Application")
exl.visible = true
set wb = exl.WorkBooks.Open(excel_path)
list_value = exl.ActiveSheet.Cells (2,1) .Value
Browser("Browser").Page("Add User").WebEdit("User Name").Set list_value

-----------------------------------------------------------
Now i have 20 text boxes here?
how do i , move to next text box and fill in the data from excel sheet.

Once i fill in all the values in the sheet.
How can i do the same thing [ ie adding new users ] , mulitple times?


RE: Want to Iterate!! - Saket - 12-30-2009

if I am getting it right, the excel contains the details of user and the 20 text boxes at your application need to filled up with these details.
if so follow these steps
loop through the number of data rows and data columns in your excel sheet
take the value from each row and column and assign it to the text boxes there.

if you need more help on this tell us how ur excel looks like and what are the fields to be filled.


RE: Want to Iterate!! - wannalearn_qtp - 12-30-2009

Hi Saket,

Thank You So much for your reply.
You are right.
Now in my application, whatever fields are present to be filled, the data for them are in the excel sheet.

------------------------------------------------------------------------------------------------------------
Code:
list_value = exl.ActiveSheet.Cells (2,1) .Value
Browser("Browser").Page("Add User").WebEdit("User Name").Set list_value
------------------------------------------------------------------------------------------------------------

Now the above , places the first field value from the excel. This works fine.
i want to move to the next field now....
basically - i have "hardecoded" the cell values. but for iterating i need to put a loop.

so,
1. I need to get row couint and colcount is it?
2. Can you please provide a pseudocode or something for me.

Thank You,
SK


RE: Want to Iterate!! - Saket - 12-30-2009

see the piece of code below
I have assumed each row in your excel contains details of one user
Code:
RowCnt = wb.Worksheets(sheetname).UsedRange.rows.Count

For nRow = 1 To RowCnt
    
        list_value = wb.Worksheets(sheetname).Cells(nRow,1).value
        Browser("Browser").Page("Add User").WebEdit("User Name").Set list_value
        list_value = wb.Worksheets(sheetname).Cells(nRow,2).value
        Browser("Browser").Page("Add User").WebEdit("User Name").Set list_value
Next
let me know how it goes.


RE: Want to Iterate!! - UjwalaK - 12-30-2009

Yes you are right Saket. This should solve the problem..


RE: Want to Iterate!! - wannalearn_qtp - 12-30-2009

Hi Saket,
Sorry i got late, But Yes It worked for me.
Thanks a ton !!!!!!

Rehards,
SK