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.

AWE's Expressions feature provides a quick and easy way to evaluate a simple BASIC expression right inside a step’s parameters. Expressions work by taking the text found between percentage signs and passing it to the BASIC expression interpreter. The result of the expression is then returned and replaces the expression (including the percentage signs) at runtime.

Using Expressions

Many actions you might want to perform with expressions are already contained in AWE 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.

Example 1: simple mathematical expression

In this example, we want a task to do a simple mathematical calculation and display the results in a message box.

  1. In the Task Builder, add the Message Box action to the task.

  2. Specify %4+4% in the Message Box action’s Message to display parameter.

    Since the phrase 4+4 is surrounded in percentage signs, AWE 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.

Example 2: expression with variable

Expressions can also contain 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.

  1. Use the Create Variable action to create a variable, NUMTOSQUARE, that will contain the user's response to the question.

  2. Create an Input Box step to display the question What number would you like squared? and populate the NUMTOSQUARE variable with the answer.

  3. 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 click Run to see how it works.

<!--- Create the variable --->
< AMVARIABLE NAME="NUMTOSQUARE">1</ AMVARIABLE>
<!--- Ask the user to enter a number --->
< AMINPUTBOX WINDOWTITLE="Enter a number" RESULTVARIABLE="NUMTOSQUARE">Which number would you liked squared?</ AMINPUTBOX>

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; the variables are capitalized here for clarity.

Because each expression is passed to the scripting language engine, any command available from a common BASIC script is available to you for use in expressions in your step parameters. Refer to the BASIC Language Reference for more details on these powerful commands.

See Also

Expression Builder

BASIC Scripts

Operators