Variable update action (<varupdate> element)
The <varupdate> element stores a value into a variable. You
must specify:
- The name of a variable
- The value that you want to store into the variable.
You can also use the Variable update action in a <description> element (see Processing a Variable update action in a description).
The value can be an arithmetic expression and can contain variables and calls to imported methods. If the value is an expression, then during macro playback the macro runtime evaluates the expression and stores the resulting value into the specified variable.
The Variable update action works like an assignment statement in
a programming language. In a Java program you could write assignment
statements such as:
boolVisitedThisScreen = true;
intVisitCount = intVisitCount + 1;
dblLength = 32.4;
strAddress ="123 Hampton Court";
With the Variable update action
you type the left side of the equation (the variable) into the Name
field on the Variable Update window and type the right side of the
equation (the value) into the Value field on the same window. To create
the equivalents of the Java assignment statements above, you would
write:
In the Name input field: | In the Value input field: |
---|---|
$boolVisitedThisScreen$ | true |
$intVisitCount$ | $intVisitCount$+1 |
$dblLength$ | 32.4 |
$strAddress$ | '123 Hampton Court' |
The value that you provide must belong to the correct data type for the context or be convertible to that type (see Automatic data type conversion).
The great usefulness of the Variable update action is due to the
facts that:
- The entity in the Value field can be an expression, and
- Expressions are not evaluated until the action is performed.