: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

  • :DEFINE
    Defines the script variable and declares the data type

  • Script variable
    Name of the script variable
    Format: script variable
    Follow the rules for variable names. For more information, see Variable Names.

  • Data type
    Data type of the variable
    Allowed values:

    • unsigned
      Positive integers without algebraic signs
    • signed
      Integers with algebraic signs
    • float
      floating-point numbers
    • string
      String or text
    For more information, see Script Variable Data Types.

  • Array size
    (Optional) Number of elements if you want to define the variable as an array
    Format: Numbers without quotation marks. You cannot use script variables.
    Allowed values: 1 to 99999
    Array name length: Up to 24 alphanumeric characters
    More information: Arrays

Notes:

  • Values that lie outside the permitted range for the declared data type are automatically converted to the target data type.
  • You can also use a :SET statement to create a script variable, but the variable can only be of the data type string or unsigned. For more information, see :SET.
  • You can only assign a different data type value if the script variable was created with a :SET statement, and the value is a positive integer or string.

Important!

  • You must declare a data type when you use a :DEFINE statement
  • Only assign a value that is permitted by the data type that you declare

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: