IF-statements are a very powerful tool. IF-statements are used to make logical decisions based on criteria specified by the user. Foxtrot supports several types of IF-statement:
- IF-statements in the Flow section compare two values
- Targeted IF-statements determine the existence or non-existence of a target
- Targeted IF-statements can also determine the value of a target’s text
If-statements are one of the most widely used actions, as they allow for customized logical commands to drive the direction of a script. Every If Action will conclude with an End If. Any Action(s) to be performed if the condition is “true” should be included between the If and End If end-caps. An Else clause may also be included, to take Action if the original condition does not hold.
In the attached file (find at the end of the article), you can find an example on how to build a script using If statements. You can download the script and try to run it. Remember to save the Foxtrot Project File to the same location as your other projects, typically in this destination: C:\ProgramData\Foxtrot Suite
It’s a good practice to split the script into several tasks. It can be very useful when the script should interface with several data sources. In this example we have split the task into four separate subtasks:
1. Foxtrot starts by creating a Workbook in Excel and creating variables:
2. Hereafter, Foxtrot performs one form of a loop, where a specific number of repeats has been defined. In this case, 4 times, and for each loop Foxtrot goes one row down and writes the data from variables:
3. In this step IF-statement is embedded in the loop. It means that for each row in the file (there are 4 rows) Foxtrot checks if the condition is true or not. If true – it performs actions between If and Else, if false - it performs actions between Else and End If.
4. The end result looks like this: