:DEFINE

Use the :DEFINE statement to define a script variable and declare the data type of the variable. For more information about variables and defining variables as arrays, see Script Variables.

Syntax 

:D[EFINE] Script variable, Data type [, Array size]

Parameters

Notes:

Warnings:

Tip: See the following script functions for modifying the data type and format of the value of a variable:

Examples

The following examples declare variables with different data types using :DEFINE statements. :SET statements assign the values of the variables:

:DEFINE &a#, unsigned
:DEFINE &b#, signed
:DEFINE &c#, float
:DEFINE &d#, string
:SET &a# = 12
:SET &b# = -5
:SET &c# = 0.50
:SET &d# = "string"

The following example automatically converts the data type of the value assigned to the variable:

:DEFINE &unsigned#, unsigned
:DEFINE &string#, signed
:SET &unsigned# = 12
:SET &string# = &unsigned#

The following example uses the CONVERT function to convert the data type of a value that is assigned to the variable:

:DEFINE &unsigned#, unsigned
:DEFINE &string#, signed
:SET &unsigned# = 12
:SET &string# = CONVERT(string,&unsigned#)

The following example uses a :SET statement to create a variable. In this case, directly assigning values to unsigned and string data types is possible.

:SET &setvar#= 12
:SET &setvar2#="string"
:SET &setvar# = &setvar2#

The following example creates and fills an array:

:DEFINE &array#, unsigned, 5
:FILL &array#[] = GET_VAR(VARA1, ARRAY)

The following example uses the FORMAT script function to round the result of an arithmetic operation (3.0 - 0.1) into a string. The script takes a common arithmetical error (Epsilon = 0.0000005) and one decimal place into account.

:DEFINE &SCRIPT_VERSION_ORIG#, float
:DEFINE &SCRIPT_VERSION_ORIG1#, float
:DEFINE &EPSILON#, float

:SET &SCRIPT_VERSION_ORIG# = 3.0
:SET &EPSILON# = 0.0000005
:P &SCRIPT_VERSION_ORIG#
:SET &SCRIPT_VERSION_ORIG# = &SCRIPT_VERSION_ORIG# - 0.1
:P BEFORE FORMAT: &SCRIPT_VERSION_ORIG#
:SET &SCRIPT_VERSION_ORIG# = &SCRIPT_VERSION_ORIG# + &EPSILON#
:SET &SCRIPT_VERSION_ORIG# = FORMAT(&SCRIPT_VERSION_ORIG#, "0.0")
:P AFTER FORMAT: &SCRIPT_VERSION_ORIG#

See also: