Create Variable

Creates a variable, which can be used to store dynamic values for use in subsequent steps. Variables are used as a storage mechanism to store data while a task is running. Once a variable is created, its contents can be viewed, set or modified within any step parameter. The value of a variable can be specified at runtime by placing the variable name in percent signs (i.e. %myvarname% will automatically be converted to its contents at runtime).

For more information, see Variables.

To set Create Variable properties

  1. In the Available Actions pane, open the Variables folder and double-click the Create Variable action or drag it into the Steps pane.

  2. In the Variable Name box, enter a name for the variable. Be sure the name is unique and does not conflict with any BASIC scripting keywords such as date, day, week, etc. One safe way to do this is to always include identifying characters, such as VAR, in variable names (for example, DateVar).

  3. If you want to give the variable an initial value, enter it in the Initial Value box. You can enter a literal value or click the percent sign (%) and use the Expression Builder to enter an expression.

  4. If you want to include a description for the variable, enter it in the Description box. The description will be displayed in the Variables tab of the Task Builder debug window.

  5. To specify additional properties, click the Advanced tab and enter the properties as described in the tables below.

  6. To set the Description tab properties, refer to Description Tab Options.

  7. To set the Error Causes and On Error tab properties, refer to Step Error Handling.

  8. When finished, click OK to save settings and close the properties dialog box.

Declaration

<AMVARIABLE NAME="text" READONLY="yes/no" PRIVATE="yes/no" ISPARAMETER="yes/no" DESCRIPTION="text">text</AMVARIABLE>

Example

This example performs a Create Variable action to create a variable named "theSampleVariable" with an initial value of "Hello world!". A Message Box action is then used to display the message "%theSampleVariable%":

<AMVARIABLE NAME="theSampleVariable">Hello world!</AMVARIABLE>

<AMSHOWDIALOG>Variable Value - %theSampleVariable%</AMSHOWDIALOG>

See Also: Create Array, Create Object, Decrement Variable, Define Type, Increment Variable, ReDim Array, Set Variable

General Tab

Property

Type

Required

Default

Markup

Description

Variable Name

Text

Yes

(Empty)

NAME="theVarName"

The name of the variable to create. It is important that this value is unique, descriptive and does not conflict with any BASIC scripting keywords (examples of names that would cause a conflict include: date, day or week, etc.).

Initial Value

Text

No

(Empty)

>The Current Value</AMVARIABLE>

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

Description (optional)

Text

No

(Empty)

DESCRIPTION="theDescription"

An optional text description that describes the purpose of the variable. This information will be displayed at design time in the Debug pane of the Task Builder under the Variables tab.

Advanced Tab

Property

Type

Required

Default

Markup

Description

Variable Type

Text (options)

No

Auto

TYPE="number"

Causes the variable to assume a specific type.

The available options are:

  • Auto: Variable will auto-detect whether it contains a number or text. The variable will adapt to the proper type when possible depending on the operation being performed.

  • Text: Variable will always be treated as text regardless of it's contents. If an operation is attempted that is only valid for numbers, an error will be thrown.

  • Number: Variable will always be treated as a number regardless of it's contents. If an operation is attempted that is only valid for numbers, an error will be thrown.

Variable is Read Only

Yes/No

No

No

READONLY="yes"

If set to YES, specifies that the variable cannot be set to a value other than that specified in the Initial Value parameter. Selecting this option is equivalent to creating a task specific constant. This parameter is set to NO by default.

Variable is private

Yes/No

No

No

PRIVATE="yes"

If set to YES, specifies that the variable is only available to the current (or parent) task and not to any sub-tasks (or child tasks) that were started with the Start Task action. If this value is set to NO, the variable will be available to sub-tasks. Set to NO by default.

Treat as parameter

Yes/No

No

No

ISPARAMETER="YES"

If set to YES, specifies that the variable will only be created if it does not already exist. This is particularly useful when a task may have parameters passed to it at runtime (that is, variables of the same name will be created automatically) but a default value should be assumed when debugging and parameters are not present.

Disguise initial value

Yes/No

No

No

>encrypted</AMVARIABLE>

If set to YES, the value entered in the Initial Value field will be encrypted.