INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

How to properly script a nested loop

How to properly script a nested loop

(OP)
STEP A
- Customer Number: No loop
- ISBN: Loop

STEP B
- Customer Number: Loop
- ISBN: Sub Loop

In other words the ISBN from STEP B is a loop within Customer Number from STEP B.

I use the i variable in both loops (Primary and sub loop of STEP B). So what I am seeing is STEP A using the first customer number and looping thru all of my ISBN numbers fine. It then goes into STEP B starts the customer number loop and assigns a value to i, then it get's into ISBN's sub loop which also assigns a value to i.

I think the extra value the sub loop is assigning to i is being carried over to when it loops thru the second time on STEP B. Hence my customer number data being pulled from the global data table happens in this order, per each iteration:

Row 1
Row 2
Row 7

So far I have tried using j inplace of i in my sub loop. That caused other data input into my app problems.

I have also tried capturing i's value before it enters the sub loop and placing that into a variable, let's say vals1.

Then when the loop for STEP B loops the second time I have it referrence the value that was set in vals1 instead of the current value of i. But that also doesn't work as expected.

I hope this is making sense to someone besides myself.

SBsteve
 

RE: How to properly script a nested loop

Nested loops can be a little tricky.  Here's an example of how they are coded:

CODE

dim MainLoop
dim SubLoop 'You need two looping variables if you want to check  every option for one value.

For MainLoop = 1 To 10
    MsgBox "This is the main Loop - cycle " & MailLoop
    For SubLoop = 1 To 10
        MsgBox "This is the Inner Loop - Cycle " & MainLoop & "Iteration " & SubLoop
    Next
Next

Can you post the code you've got?  It'll make it easier to debug it.

Cheers,
Dave

"Yes, I'll stop finding bugs in the software - as soon as you stop writing bugs into the software."  <-- Me

For all your testing needs: forum1393: Systems & Software Testing

RE: How to properly script a nested loop

(OP)
Thanks Dave.

With some help of another message board I got the help I needed yesterday.

Here is my code with the nested loop:

===========================================================

'CREATE AN ADDITIONAL CUSTOMER (First Loop)

Dim i, j, CustomerNumber, ISBNnumber
DataTable.ImportSheet "C:\QOE Data - UAT1.xls" ,"Data" ,"Global"
RowCnt = DataTable.GetSheet("Global").GetRowCount

For i  = 1 To RowCnt
    DataTable.GetSheet("Global").SetCurrentRow(i)

    DataTable.SetNextRow
    
    CustomerNumber = Datatable.Value("Customer_Num","Global")
    OracleFormWindow("Sales Order").SelectMenu "File->New"
    OracleFormWindow("Sales Order").OracleTabbedRegion("Order Information").OracleTextField("Customer Number").SetFocus
    OracleFormWindow("Sales Order").OracleTabbedRegion("Order Information").OracleTextField("Customer Number").Enter CustomerNumber

msgbox RowCnt
msgbox i

If i = RowCnt + 1 Then
Browser("Browser").Page("Oracle Applications 11i").Sync
Browser("Browser").Close
End If

'CREATE SECOND ISBN LIST (Nested Loop)

DataTable.ImportSheet "C:\QOE Data - UAT1.xls" ,"Data" ,"Global"
Dim RowCnt3, val3
RowCnt3 = DataTable.GetRowCount
For j = 1 To RowCnt3
    DataTable.SetCurrentRow(j)
    If Trim(DataTable("ISBN",dtGlobalSheet)) = "" Then
    j = j - 1
        Exit For
    End If
Next

'Define ISBN rows
If  RowCnt3 <>  j Then
    RowCnt3 = j
End If

'Loop through ISBN rows
For j = 1 To RowCnt3
    DataTable.SetCurrentRow(j)
    val3 = Datatable.Value("ISBN","Global")
    
    msgbox j
    
    If j = 1 Then
    OracleFormWindow("Sales Order").OracleTabbedRegion("Line Items").OracleTextField("Ordered Item").SetFocus
    OracleFormWindow("Sales Order").OracleTabbedRegion("Line Items").OracleTextField("Ordered Item").Enter val3

    'else If j < 16 Then
    else If j < RowCnt1 Then
    OracleFormWindow("Sales Order").OracleTabbedRegion("Line Items").OracleTextField("Ordered Item_"&j).SetFocus
    OracleFormWindow("Sales Order").OracleTabbedRegion("Line Items").OracleTextField("Ordered Item_"&j).Enter val3
    
   else If RowCnt1 => 16 Then
   OracleFormWindow("Sales Order").OracleTabbedRegion("Line Items").OracleTextField("Ordered Item_15").SetFocus
  OracleFormWindow("Sales Order").OracleTabbedRegion("Line Items").OracleTextField("Ordered Item_15").InvokeSoftkey "DOWN"
  OracleFormWindow("Sales Order").OracleTabbedRegion("Line Items").OracleTextField("Ordered Item_15").SetFocus
  OracleFormWindow("Sales Order").OracleTabbedRegion("Line Items").OracleTextField("Ordered Item_15").Enter val3

   End If
end if
  end if
Next
 
'Do some work

Next

'EXIT APP

Browser("Browser").Page("Oracle Applications 11i").Sync
Browser("Browser").Close
  
==========================================================

As you can see I did have to use both the "i" and "j" variables to make this work, just as you had stated above.

Thanks,
SBsteve

RE: How to properly script a nested loop

Happy to help - though you do seem to have multiple sub loops in there.  Any reason why that's not just a single subloop?

Cheers,
Dave

"Yes, I'll stop finding bugs in the software - as soon as you stop writing bugs into the software."  <-- Me

For all your testing needs: forum1393: Systems & Software Testing

RE: How to properly script a nested loop

(OP)
Dave,

  I hope this answers your question...

  In my script I have two basice steps, STEP A and STEP B.
In STEP A there is one loop. In STEP B there is a loop and a nested loop within that loop.

  Due to how my Oracle app is setup and the fileds that I need to click in and enter data, this is the best option for me and it works.

Thanks,
SBsteve

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close