Expressions

What are Expressions?

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. The Expression Builder provides a quick and convenient way to create and evaluate Automate BASIC expressions from directly within the parameters of a task step. Expressions work by taking the text found between percentage (%) signs and passing it to the Automate BASIC expression interpreter. During runtime, the BASIC interpreter replaces the original expression (including the percentage signs) and returns the expression's resulting value instead.

Using Expressions

Many actions that normally require expressions may already be built into Automate activities. However, you can use expressions to further expand an action's capabilities. For instance, you can build expressions that resolve complex, dynamic data at runtime with the use of variables, functions, extended functions, and operators.

Example 1 - Simple Mathematical Expression

In the following example, a task runs a single step that performs a simple mathematical calculation and displays the results in a message box. To create this task:

  1. In the Task Builder, add a Dialog - Message activity to the Steps panel.

  2. From the General properties of this activity, enter %7+7% in the Message to display parameter (as shown below) and then click OK to save changes.

  3. From the Task Builder's ribbon, click Runto start the task.

Since the phrase 7+7 is surrounded in percentage signs, Automate knows that it should try to resolve the expression and not display it literally. To resolve the expression, at runtime, the value between the percentage signs is passed to the BASIC expression interpreter, where it is processed and the result is returned. A message dialog should appear with the value of 14 (as shown below).

Example 2 - Expression with Variable

Expressions can also contain Automate variables. Taking the previous example a step further, assume we now want the task to give the user the ability to enter a number they want squared.

  1. Use the Variable - Create activity to create a variable named NUMTOSQUARE with the initial value of 1. This variable will be used during runtime to retain the user's response to the question.

  2. Use the Dialog - Input activity as the second step to display the question What number do you want squared? and populate the NUMTOSQUARE variable with the answer.

  3. Use a Dialog - Message activity as the last step which will display the result by use of the following expression multiplying the variable by itself: %NUMTOSQUARE *2%.

The complete task is displayed below in AML format. To run the task, copy and paste the code below directly into the Steps panel of the Task Builder.

Copy
<!-- Create the variable. -->
<AMVARIABLE NAME="NUMTOSQUARE" VALUE="1" />
<!-- Ask the user to enter a number. -->
<AMSHOWDIALOG ACTIVITY="input" MESSAGE="What number do you want squared?" RESULTVARIABLE="NUMTOSQUARE" />
<!-- Perform the calculation using an inline expression. -->
<AMSHOWDIALOG WINDOWTITLE="Result" RESULTVARIABLE="NUMTOSQUARE">The answer is: %NUMTOSQUARE*2%</AMSHOWDIALOG>

Notes

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 Variable - Create activity.

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.