Set Variable Icon Action

Set Variable

Declaration

<AMSET VARIABLENAME="text (variable name)">text (value to set)</AMSET>

OR

<AMSET VARIABLENAME="te">AM125QfdSMYkv0zoNy+RdvlmA==aME</AMSET>

See Also

Create Array| Create Object | Create Variable | Define Type | Increment Variable | ReDim Array | Return

Description

Changes the contents of an already existing variable.

Practical Usage

Variables are used as storage mechanism to store data while a task is running. For more information see Variables. Once a variable is created, its contents can be displayed at runtime by placing the variable name in percent signs (i.e. %myvarname% will automatically be converted it it's contents at runtime).

Parameters

General Properties

Property

Type

Required

Default

Markup

Description

Variable to increment

Text

Yes

(Empty)

VARIABLENAME="thecurrentdate"

The name of the variable to change.

Value

Text

Yes

(Empty

VALUE="The current date is %Now()%"

The value that the variable should be changed to. As with all parameters, this value may be literal or an expression (if surrounded by percent % signs).

Using Variables

All variables must be created before they can be used. This is done using the Create Variable action. Once created, variables can be set using the Set Variable action, or by certain actions that support populating variables. To get data out of the variables in any action parameter, simply surround the variable name with percentage % signs (i.e. %varname%). Remember not to use percentage signs when specifying the name of a variable to populate, percentage signs are only needed to get data out.

Description Properties

The Description tab allows you to customize the text description of any step as it appears in the Task Builder's Steps Pane.

More on setting custom step description

Error Causes Properties

The Error Causes tab properties lets you instruct a task step to react only to specific errors or ignore certain errors that should cause it to fail.

More on Error Causes properties

On Error Properties

The On Error tab properties lets you determine what the task should do if a particular step encounters an error as defined in the Error Causes properties.

More about On Error properties

Additional Notes

Expressions, Variables & Functions

A percent sign is used as a special character in AutoMate to indicate the beginning and end of an expression. This allows variables, functions and other expressions to be entered in any text parameter of a task's properties. For example: %1+1% inside a task will resolve to 2 at runtime. A more elaborate example is %FileDateTime(myFile)% which results to the date/time of myFile. To help construct expressions, you can open Expression Builder by clicking the Insert Expression (%) button or by pressing F2.

More on expressions

More on variables

More on functions

More on extended functions
More on the expression builder

Example

NOTE: The code below can be copied and pasted directly into the Steps pane of the Task Builder.

 

Sample 1 - A Set Variable action used to change the initial value of an existing variable.

 

<AMVARIABLE NAME="myVariable">AutoMate</AMVARIABLE>

<AMSHOWDIALOG WINDOWTITLE="CURRENT VALUE">The current value of myVariable is:

%myVariable%</AMSHOWDIALOG>

<AMSET VARIABLENAME="myVariable">Business Process Automation</AMSET>

<AMSHOWDIALOG WINDOWTITLE="NEW VALUE">The new value of myVariable is:

%myVariable%</AMSHOWDIALOG>

 

 

Sample 2 - A Set Variable action used to populate a value into a variable created with no initial value.

 

<AMVARIABLE NAME="myVariable"></AMVARIABLE>

<AMSHOWDIALOG WINDOWTITLE="CURRENT VALUE">The current value of myVariable is:

%myVariable%</AMSHOWDIALOG>

<AMSET VARIABLENAME="myVariable">Business Process Automation</AMSET>

<AMSHOWDIALOG WINDOWTITLE="NEW VALUE">The new value of myVariable is:

%myVariable%</AMSHOWDIALOG>

 

 

Sample 3 - Variable multiplication - This task describes how to multiply the initial value of two variables using the Set Variable action and display the results in a message box.

 

<AMSHOWDIALOG>This task describes how to multiply the initial value of two variables using the

‘Set Variable’ action and display the results in a message box. This action changes

the contents of an already existing variable. As with all parameters, this value

may be literal or an expression (if surrounded by percent signs). This will work with

other calculations as well (i.e. addition "+", subtraction "-", division "/").</AMSHOWDIALOG>

<AMVARIABLE NAME="var1">30</AMVARIABLE>

<AMVARIABLE NAME="var2">10</AMVARIABLE>

<AMVARIABLE NAME="var3"></AMVARIABLE>

<AMSET VARIABLENAME="var3">%var1 * var2%</AMSET>

<AMSHOWDIALOG>%var1% multiplied by %var2% results is %var3%</AMSHOWDIALOG>

 

↑ [Return to Top]