LOTUSSCRIPT LANGUAGE


Dim statement
Example

Declares variables.

Syntax

{ Dim | Static | Public | Private } variableDeclaration [ , variableDeclaration ]...

Elements

Dim | Static | Public | Private


variableDeclaration Usage

The Public keyword cannot be used in a product object script or %Include file in a product object script, except to declare class members. You must put such Public declarations in (Globals).

Explicit declarations and implicit declarations

You can declare a variable name either explicitly or implicitly. The Dim statement declares a name explicitly. A name is declared implicitly if it is used (referred to) when it has not been explicitly declared, or when it is not declared as a Public name in another module being used by the module where the name is referred to. You can prohibit implicit declarations by including the statement Option Declare in your script.

Specifying the data type

Either dtSuffix or As type can be specified in variableDeclaration, but not both. If neither is specified, the data type of variableName is Variant.

The data type suffix character, if it is specified, is not part of the variable name. When the name is used (referred to) in the script, it can be optionally suffixed by the appropriate data type suffix character.

Declaring arrays

For a fixed array, Dim specifies the type of the array, the number of dimensions of the array, and the subscript bounds for each dimension. Dim allocates storage for the array elements and initializes the array elements to the appropriate value for that data type (see "Initializing variables," later in this section).

For a dynamic array, Dim only specifies the type of the array. The number of dimensions of the array and the subscript bounds for each dimension are not defined; and no storage is allocated for the array elements. The declaration of a dynamic array must be completed by a later ReDim statement.

Arrays can have up to 8 dimensions.

Array subscript bounds must fall in the range -32,768 to 32,767, inclusive.

Declaring lists

A list is initially empty when it is declared: it has no elements, and no storage is allocated for it. An element is added to a list when the list name with a particular list tag first appears on the left-hand side of an assignment statement (a Let statement or a Set statement).

If the character set is single byte, Option Compare determines whether list names are case sensitive. For example, if Option Compare Case is in effect, the names "ListA" and "Lista" are different; if Option Compare NoCase is in effect, these names are the same. If the character set is double byte, list names are always case and pitch sensitive.

Declaring object reference variables

If type is the name of a class and the keyword New is not specified, the initial value of the declared object reference variable is NOTHING. To assign another value to an object reference variable, use the Set statement later in the script.

Dim variableName As New className generates executable code. When you save a compiled module, module-level executable code is not saved, so be careful about using such a statement at the module level. Your Lotus software may prohibit you from placing executable statements at the module level.

You may prefer to declare the object reference variable at the module level with Dim variableName As className, which is not executable code, then use a Set statement (which is executable code) in a procedure to bind the object reference variable to an object.

The New keyword is not valid in an array declaration or a list declaration.

Initializing variables

Declaring a variable also initializes it to a default value.


Visibility of declarations

The default visibility for a declaration at the module level is Private, unless Option Public has been specified.

The default visibility for a variable declaration within a class is Private.

Public and Private can only be used to declare variables in module or class scope. Variables declared within a procedure are automatically Private; members of user-defined data types are automatically Public. Once created, these cannot be changed.

Example
See Also