An expression, in programming, is a combination of symbols that represents a value. The expression is interpreted according to the rules of the programming language and a value is returned.
AutoMate's Expressions feature provides a quick and easy way to evaluate a simple AutoMate™ BASIC expression right inside a step’s parameters. Expressions work by taking the text found between percentage signs and passing it to the AutoMate™ BASIC expression interpreter. The result of the expression is then returned and replaces the expression (including the percentage signs) at runtime.
Many actions you might want to perform with expressions are already contained in Automate actions. However, you can use expressions to expand on the available actions. You can build expressions to resolve dynamic data at run time using functions, variables, constants and operators.
In this example, we want a task to do a simple mathematical calculation and display the results in a message box.
In the Task Builder, add the Message Box action to the task.
Specify %4+4% as the Message action’s “Message to display”
Since the phrase 4+4 is surrounded in percentage signs, AutoMate knows that it should try to resolve this value and not display it literally. To resolve the expression, the value between the percentage signs is passed to the expression evaluator, where it is processed and the result is returned. At runtime, only the result (8) will be displayed.
Expressions can also contain AutoMate™ variables inside the expression. Taking the previous example a step further, assume we now want the task to give the user the ability to enter a number he would like squared.
Use the Create Variable action to create a variable, NUMTOSQUARE, that will contain the user's response to the question.
Create an Input Box step to display the question What number would you like squared? and populate the NUMTOSQUARE variable with the answer.
Create a Message Box
step that displays the result by use of an expression multiplying the
variable by itself. %NUMTOSQUARE * NUMTOSQUARE%
The task is shown below. You can copy and paste this into the Task Builder and press the run button to see how it works.
<!--- Create the variable --->
<!--- Ask the user to enter a number --->
<AMINPUTBOX WINDOWTITLE="Enter a number" RESULTVARIABLE="NUMTOSQUARE">Which number would you liked squared?</AMINPUTBOX>
<!--- Perform the calculation using an inline expression --->
<AMMESSAGEBOX>%NUMTOSQUARE * NUMTOSQUARE%</AMMESSAGEBOX>
Notice that we first had to create the variable we intend to use. All variables to be passed into a scripting language, either explicitly through the use of a BASIC script step or implicitly through the use an expression, need to be created first. You can accomplish this using the Create Variable action.
Variable names are not case sensitive in AutoMate™; the variables are capitalized here for clarity.
Because each expression is passed to the scripting language engine, any command available from a common AutoMate™ BASIC script is available to you for use in expressions in your step parameters. Refer to the AutoMate™ BASIC Language Reference for more details on these powerful commands.