Often times in scripts, we will want to repeat or loop through something so we can do this multiple times. In this case we are going to add a loop into our script so that it creates more than one order.
First we will need to record another step in our Flight application. After we insert the order, we will need to record clicking on the "new order" button.
Now we need to add some looping logic. First we are going to add another column to our spreadsheet. We can call it "DATE" and we will list several dates. We will configure our script loop through our spreadsheet and create a new order for each date.
Now we will add some VBScript code that will declare the variable we will use. A variable is like a storage location for data. We will use our variable RowCount to store the numerical value of the row count.
We will use the GetRowCount method to find out the number of rows in our spreadsheet. In this case its 3.
Then we will start our loop.
After we complete the actions of our loop we need to tell our script to go to the next row, count down our RowCount, and then do it again until our RowCount is 0 When our RowCount is 0 the loop will end.
This is what the total script looks like:
This is what our exported spreadsheet looks like, note that is captured all 3 prices:
There are other kinds of loops:
For...Next Loop - runs code a specified number of times
For Each...Next statement - runs code for each item in a collection or each element of an array
Do...Loop statement - loops while or until a condition is true much like a while loop
Try converting your while loop into the various different types of loops. Which one was easiest to write?