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 typeAn array of the specified dimensions, all values initialized with the specified type (see below).
name := expressionInitialized with the specified expression.
name As typeInitialized 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:

AnyAllow any type, initialize with EMPTY.
DoubleFractional, initialize to 0.0.
FloatFractional, initialize to 0.0.
HashHash, initialize to a blank hash.
IntegerInteger, initialize to 0.
LongInteger, initialize to 0.
SingleFractional, initialize to 0.0.
StringString, 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)

This is a testing version.
It may be incomplete, and have more bugs (or features) than the public live version at planetscentral.com.