DIM Statement

Declares variables and allocates storage space.

DIM varname[] as {Integer|String}

DIM varname as {Integer|String}

 

Arguments

varname      Name of the variable; follows standard variable naming conventions.

 

Remarks

Variables can only be declared as Integers or Strings. All variables must be initialised before their value is read. You can also use the Dim statement with empty parentheses to declare a dynamic array. After declaring a dynamic array, any value can be inserted into the parenthesis. 

When you use the Dim statement in a function, the variable is only valid for that function. If you want a variable defined in a function to be available after the function has exited then use GLOBAL instead of DIM 

 

Examples

The following examples illustrate the use of the Dim statement:

Dim Data[] as Integer

Dim Answer as String

Dim count as Integer

 

Initialisation of variables

If the variable is not an array then it can be initialised

Dim Answer as String = "Hello"

Dim count as Integer = 0

 

Using Arrays

Data[4] = 3                   // Setting a value in an integer array

datastring[] = "Line 1"    // Adding a string to the end on a string array

datastring[] = "Line 2"    // Adding a string to the end on a string array