Micro Focus QTP (UFT) Forums
FOR loop with nested CASE - 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: FOR loop with nested CASE (/Thread-FOR-loop-with-nested-CASE)



FOR loop with nested CASE - wheelercha - 12-11-2009

Hi All,

I have a unique situation where I must click on an image on the page to reveal the list of items then I have to set the webelement to the desired item in the list. I want to create multiple rows with a FOR statement and it works when I use the same item name each time:

Code:
for i =1 to 3
    datatable.setcurrentrow(i)
    returnvalue=datatable.value("invoiceNumber","Add_Multiple_Invoices")
Browser("Suppliers and Invoices").Page("Suppliers and Invoices").Image("spacer").Click
'Browser("Suppliers and Invoices").Page("Suppliers and Invoices").WebElement("Cleaning Supplies").Click


I want to incorporate a CASE statement or some code that will allow me to put a different value maybe from a table instead of it always being "Cleaning Supplies" . So something like this maybe :

Code:
for i =1 to 3
    datatable.setcurrentrow(i)
    returnvalue=datatable.value("invoiceNumber","Add_Multiple_Invoices")
Browser("Suppliers and Invoices").Page("Suppliers and Invoices").Image("spacer").Click
Select Case Category
        Case i = 1
returnCategory=datatable.value("Category","Add_Multiple_Invoices")

Any ideas on what I am doing wrong? The For Loop works, the Case does not.

Thanks,
Charles


RE: FOR loop with nested CASE - nil - 12-11-2009

Hi Charles
below is Select case Syntax

Code:
MyVar="Red"
Select Case MyVar
      Case "red"     document.bgColor = "red"
      Case "green"   document.bgColor = "green"
      Case "blue"    document.bgColor = "blue"
      Case Else      MsgBox "pick another color"
End Select



RE: FOR loop with nested CASE - upadhyay40 - 12-12-2009

Hi charles,

If you are using web application and want to click or select each webList item then you can probably use index property for selecting each and every list item with the help of For loop, may be you will solve your problem.

Thanks
Mahesh