How to use variables correctly

Articles, advices, FAQ, etc.

How to use variables correctly

Postby Oleg » Thu Jun 05, 2014 12:31 pm

Usage of variables in expressions
As a rule, when any action is configuring, it is possible to use variables. To specify a variable in an expression (in a string) it is enough to put the variable name within braces "{" and "}".

How it works.
When any action works the RoboTask tries to expand insets of variables in the expression. In other words, it replaces the variable name with the variable value in the expression.
The algorithm is easy:
At first, the program scans the source line for expressions which are put in braces;
  • If such expressions are found, the RoboTask tries to find the variable value using the variable name and parameters (if the parameters are specified);
  • If the variable exists, the RoboTask replaces the expression in braces with the found value;
  • If such variable desn't exist, the RoboTask leaves the source expression without any changes.

Assigning some value to a variable
Overwhelming majority of actions execute certain operations and demand to save some values to data transfer in other actions of the task. Specifying the variable name to save the value, the variable name has to be specified explicitly. A variable name is just a set of Latin symbols and figures without any blanks. Braces are not to be specified in this case.
But there is an exception to this rule. Beginning from the version 5.3 a variable name is possible to be formed with using of other variables. But you must understand why it is necessary.

What happens if you specify braces in the variable name (that is, do insets of other variables in the expression):
  • The RoboTask computes the final expression which is the variable name. In other words, it replaces expressions in braces with variable values.
  • After that, it checks if it is permissible to use the got name as a variable name. Otherwise, the RoboTask generates warning and skips the operation of assigning value.
  • Only after checking, the RoboTask assigns the specified value to the variable with such name.

The usage of such compound names allows to get more flexibility when writing a task in some cases. But if this method is hard to understand, it is better to avoid it. It is necessary only to specify the variable name explicitly without any braces.
Oleg Yershov
Site Admin
Posts: 2057
Joined: Thu Jan 01, 1970 1:00 am

Return to Articles

Who is online

Users browsing this forum: No registered users and 1 guest