<< Click to Display Table of Contents >> Navigation: Several practical recommendations > Using Variables in Tasks > Usage of Variables |
For building complex automation schemes, RoboTask provides two types of variables that you can use in actions and triggering events:
•System variables that are pre-defined.
•User variables that you can define yourself.
When you insert a variable name as a parameter or part of a parameter in an action or triggering event, the variable content is processed, instead of the variable name.
For example, if you want to show a message containing the day of the week, you should use the {DayOfWeek} variable.
When you run the task that contains the {DayOfWeek} variable, the variable is replaced by the name of current week day. If you insert this variable in a Show Message action that includes the message defined as "Today {DayOfWeek}!", when you run this task on Wednesday, the following message displays: "Today Wednesday!".
You can use as many variables as you need in an event or action. Any time that you define the same parameter many times, you should use a variable. This allows you to change the variable in one place and all your tasks that contain the variable update automatically.
The Usage of variable names in actions.
Beginning with the version of RoboTask 5.3 all the actions where variables are assigned allow to use other variables in the variable name. That can be useful, for example, when creating enumerated variables like these:
Line1
Line2
...
Line10
In this case it is possible to specify a variable name like Line{num}, where num contains the ordinal iteration number of a cycle. Thereby, it is possible to create pseudo array.
However, it is strongly recommended not to abuse that feature. Although such approach provides more flexibility, it is easy to get confused in variables names. Therefore we advise to specify the variables names explicitly, if it is possible to avoid dynamic names.
Variables that Contain Other Variables
You can even use variables within other variables; this is useful if you want to specify a value of a variable for other variables. For example, you can define a variable with a name {Yesterday}. {Yesterday} contains another variable with a value {MonthIncDays(-1)}/{IncDays(-1)}/{YearIncDays(-1)}. When you use the {Yesterday} variable, it returns yesterday's date.
To make your tasks even more powerful, you can use variables as arrays. This means you can specify more than one values separated with commas. To access the first value, use index 0: {MyVar(0)}. To access the second value, use index 1: {MyVar(1)}. And so on.
For example, if to add a variable with name {MyArray} and value One, Two, Three, you can use that variable as shown below:
•{MyArray} = One, Two, Three
•{MyArray(0)} = One
•{MyArray(1)} = Two
•{MyArray(2)} = Three
Another example:
•{MyArray} = "First item", "Second item", "Third item"
•{MyArray(0)} = First item
•{MyArray(1)} = Second item
•{MyArray(2)} = Third item
Related Topics
Saving of a result into a variable
Rules for using variables in expressions
How to use variables correctly