Dim [Local|Static|Shared] name [initializer],...
Create a variable.
You can create variables of different kind:
- Local variables variables exist during the current subroutine or file only. This is the default.
- Static variables exist during the current script execution.
- Shared variables exist for all scripts you execute.
If you do specify a variable kind, you can omit the Dim keyword, i.e. Dim Static a is equivalent to Static a.
If the variable you create is indeed new, it will be initialized with the initializer (if no initializer is specified, it will start EMPTY). If the variable already exists, the initializer will be evaluated, but the variable keeps its original value.
The initializer can have the following forms:
name(expr, ...) | An array of the specified dimensions, all values EMPTY. |
name(expr, ...) As type | An array of the specified dimensions, all values initialized with the specified type (see below). |
name := expression | Initialized with the specified expression. |
name As type | Initialized with the default value for the specified type. |
The type can be a structure name defined with Struct to initialize the variable (or the array elements) with fresh instances of that structure, or one of the following:
Any | Allow any type, initialize with EMPTY. |
Double | Fractional, initialize to 0.0. |
Float | Fractional, initialize to 0.0. |
Hash | Hash, initialize to a blank hash. |
Integer | Integer, initialize to 0. |
Long | Integer, initialize to 0. |
Single | Fractional, initialize to 0.0. |
String | String, initialize to "". |
Examples:
Dim a, b, c % Three local variables Dim four = 4 % Local variable with value 4 Dim i As Integer % Local variable, integer Dim mat(10,10) % 10x10 matrix (2-D array) Dim ps As MyStruct % Structure Dim Shared gv % Shared variable
Version Differences: PCC 1.x supports only simple value initialisations, and does not support arrays, hashes, or As initialisation.
Since: PCC 1.0.6, PCC2 1.99.8
See also: Dim (Elementary Function)