Self-defined variables (#VAR, #ENDVAR, #DELETE)
Self-defined variables are created and initialised as required in the NC main program or subroutine after the program name in a declaration block which starts with #VAR and ends with #ENDVAR .
Notice
Self-defined variables have prefix identifier V.P. , V.S. and V.L. They may be assigned values in REAL format. As of Build V2.11.2032.08 self-defined variables are available with the prefix identifier V.CYC..
Syntax of Creating a declaration block for self-defined variables: | |
#VAR | Start of declaration block |
: |
|
: | Declaration and initialisation part |
: |
|
#ENDVAR | End of declaration block |
Due to the introduction of V.CYC. variables, the following extensions are available for all types of self-defined variables (as of: V2.11.2032.08, V2.11.2832.00, V3.1.3079.41, V3.1.3107.30)
Besides specifying the variable name, the declaration also includes a definition of the data type and an initial value. The variable is assigned the initial value of each data type without assigning an initial value. If a data type is not specified, the variable is always created in REAL format.
Syntax of the declaration and initialisation: |
V.P | S | L | CYC.<name> : <data_type> = <initial:value> | "<initial_string>" |
<name> | User-defined name of the self-defined variable |
<data_type> | Data type identifiers (optional): BOOLEAN SGN08, UNS08 SGN16, UNS16 SGN32, UNS32 REAL64 STRING[i] where <i>:= 0..126 |
<Initial_value>, "<Initial_string>" | Initial value or string of the variable (optional) depending on data type |
Programing Example
Create variables with and without type declaration
%test_var_def_1
:
#VAR
V.P.VAR_1
V.P.VAR_2 = 10.67
V.P.VAR_3 : UNS32 = 10
V.L.NAME_1 : STRING[20] = "BASEPLATE"
V.L.VAR_1 : REAL64 = 23.45
V.L.VAR_2 : SGN08
#ENDVAR
For a better overview, initialisation of a variable array can be written across several NC lines using the "\” character.
%test_var_def_2
:
#VAR
V.P.ARRAY_1[3][6] = [10,11,12,13,14,15, \
20,21,22,23,24,25, \
30,31,32,33,34,35 ]
V.L.MY_ARRAY[3][6] = [10,11,12,13,14,15, 20,21,22,23,24,25, 30,31,32,33,34,35]
#ENDVAR
Notice
Access to array variables starts with index 0. In the above example, access V.L.MY_ARRAY[0][5] then supplies the value 15.
Self-defined variables and variable arrays can also be deleted in the NC program. The #DELETE command is provided for this.
Syntax |
#DELETE V.<name> {, V.<name>} |
Programing Example
#DELETE V.P.ARRAY_1, V.L.MY_ARRAY, V.P.VAR_1, V.L.VAR_1, V.S.VAR_1
In addition, the SIZEOF and EXIST functions are provided (see Section Arithmetical expressions <expr>) to determine the dimensional size of variable arrays and check for the existence of self-defined variables.
Programing Example
The EXIST request for a self-defined V.S. array variable (with any valid index) checks whether this variable was already defined in a previous NC program or if this variable must still be defined:
…
N10 $IF EXIST[V.S.EXAMPLE[0]] == TRUE
N20 V.S.EXAMPLE[2] = 10 ;assign a value to V.S. variable[2]
N30 $ELSE
N40 #VAR
N50 V.S.EXAMPLE[5] = [1,2,3,4,5 ]
N60 #ENDVAR
N70 $ENDIF
…
M30