NOTE: This feature is only available in the Professional version of AutoMate
Expressions provide a quick and easy way to evaluate a simple AutoMate™ BASIC expression right inside a step’s parameters instead of writing an entire BASIC script. 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.
Consider the following example: we want a task to do a simple mathematical calculation and display the results in a message box. To do this: in the Task Builder, add the Message Box step to the task specify %4+4% as the Message step’s “Message to display” parameter. 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 will be displayed which is 8.
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 (that is, multiplied by itself). To perform this operation, we first create the variable which will contain the users response to the question (What number to square?), then we display the question using the Input Box action, this step will populate the variable specified with the answer. In the last step, we simply display the result by use of an expression multiplying the variable by itself. The task is shown below (hint: 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 through as expressions to be used in your step parameters. Refer to the AutoMate™ BASIC Language Reference for more details on these powerful commands.
Introduction to Functions