:DEFINE

Use the :DEFINE statement to explicitly define a script variable and formally declare its data type. For comprehensive details regarding variables and configuring variables as arrays, see Script Variables.

Syntax

: [DEFINE] Script variable, Data type [, Array size]

Parameters

Parameter Description Format / Allowed Values
Script variable

Specifies the target name of the script variable.

You must follow the standard rules for variable names. For more information, see Variable Names.

Script variable format
Data type

Declares the specific data type of the variable:

  • 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.

Keyword
Array size

(Optional) Determines the number of elements if you want to define the variable as an array.

Array name length: Up to 24 alphanumeric characters. For more information, see Arrays.

1 to 99999 (defined via numbers without quotation marks or script variables)

Important Considerations

Keep the following data type rules and formatting behaviors in mind when utilizing this script statement:

  • Important! You must declare a valid data type when you use a :DEFINE statement.
  • Important! You must strictly assign a value that is permitted by the data type that you declared.
  • If you supply values that lie outside the permitted range for the declared data type, the system automatically converts them to the target data type.
  • You can also use a :SET statement to create a script variable on the fly, but doing so restricts the variable to either the string or unsigned data type.
  • If a script variable was created dynamically with a :SET statement, you can only assign a different data type value to it if the value is a positive integer or a string.
  • Tip: Utilize the CONVERT and FORMAT script functions to programmatically modify the data type and format of a variable's value.

Examples

Array Size Assignment

The following example sets and later changes an array size using variables.

:SET &SIZE# = 3

:DEFINE &ARR#string&SIZE#

:SET &SIZE# = 5

:DEFINE &ARR#string&SIZE#

Data Type Declarations

The following examples declare variables with different data types using :DEFINE statements. :SET statements then 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"

Automatic Data Type Conversion

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#

Explicit Data Type Conversion

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#)

Variable Creation via SET

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#

Array Initialization

The following example creates and fills an array.

:DEFINE &array#, unsigned, 5

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

Formatting Arithmetical Results

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: