Skip to content

Dim

Description

This statement declares a list of variables. Each variable declaration must be separated by a comma. The variable only exists inside the function.

To declare an array variable, you must supply a comma-separated list of the number of elements for each dimension enclosed in square brackets. You can only declare static arrays, meaning you cannot resize the number of elements after declaration.

Declaring a variable is optional. The 'Let' statement automatically declares a variable before assigning a value to it, unless it’s an array variable.

The variable name must start with a letter, followed by any number of alphanumeric characters. Operators, quotes, and underscores are not allowed in a variable name.

Syntax

Dim <Variable> [,<Variable>]

Where square brackets indicate optional parts of the statement and ‘…’ indicates more occurrences are allowed.

Sample

Dim nAmt, aVals[10], iCount, nRes

Let nAmt = 0.75
// Calculate 75% of each value in the array
For iCount = 0 to 9 do
    Let aVals[iCount] = iCount + 1
    Let aVals[iCount] = aVals[iCount] * nAmt
Loop

// Calculate total of values
For iCount = 0 to 9 do
    Let nRes = nRes + aVals[iCount]
Loop

Return nRes

The result of the above function is 75% of the values in the array.

Notes

  • Prior to version 8, it was not possible to declare more than one variable with each DIM statement.