DIM
Declaration of work variables and work variable arrays.
WebVue support - Yes.
Mode |
Usage |
Syntax |
- | Variable | 1 |
- | Array | 2 |
Syntax 1
DIM VarName As Type [, VarName2 As Type, ...];
There is no return type.
Argument |
Meaning |
VarName |
The name by which the variable is to be known. |
Type |
The type of variable (INTEGER, LONG, LONGLONG, SINGLE, DOUBLE or STR). |
Execution
A variable may be declared in the header block of either a function or program (outside the functions). If it is declared in a program header block, it will be available to all functions. If it is declared within a function, it will only be available to that function.
If a variable is to be substituted, the declaration must be made inside a Sub function, not globally in the program header nor passed as an argument from a Run Program animation. See example 1 below.
Syntax 2
DIM VarName [Size1] [Size2] As Type [, VarName2 As Type, ...];
There is no return type.
Argument |
Meaning |
Size1, Size2 |
The number of elements for each dimension. |
Execution
An array variable may be declared in the header block of either a function or program (outside the functions). If it is declared in a program header block, it will be available to all functions. If it is declared within a function, it will only be available to that function.
The maximum number of dimensions for an array variable
is 10. For example,, TAB[i][j][k] is an array with three dimensions.
The maximum number of array elements in a particular function is 600 less
the number of functions in the program. The array index starts at 0.
During iteration of an array the mimic display is frozen. Iterating a large array is very time consuming and should be avoided whenever possible.
Example 1
'Substitution - so the variable Vartext cannot be global
Sub main ()
Dim VarText as str;
Vartexte = "API_PP.RACK0_5.1.I0";
@INPUTTEXT=?Vartext;
End Sub
Example 2
SUB Main()
DIM i As integer;
DIM j As integer;
DIM strString1 As str;
DIM intArray1 [3][5] As integer;
'The table always starts at value 0;
strString1 ="1";
'Display strString1 value
PRINT (strString1);
FOR (i=0;i<3;i=i+1)
FOR (j=0;j<5;j=j+1
intArray1[i][j]=1;
'Display the table value
PRINT (intArray1[i][j]);
NEXT
NEXT
END SUB
For more examples, select the Example link above.