Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to properly script a nested loop

Status
Not open for further replies.

SBsteve

Technical User
May 14, 2008
8
US
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
 
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
 
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
 
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
 
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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top