DIMENSION Statement

The DIMENSION statement is necessary to declare the dimensions of array variables before they are used within a program.

Format

DIM[ENSION] var1(n [, m]) [, var2 (n [, m]) ...]

Parameter(s)

var...

Name of the array.

n[, m]

Contains the maximum dimensions of the array, with n and m being whole number constants. Note that mvBASIC array dimensions are 1-based.

Description

The DIMENSION statement defines the dimensions of an array variable and must be used prior to any reference to the array in the program. For a matrix (a two-dimensional array), use the DIMENSION statement to set the maximum number of rows and columns available for the elements of the array. For a vector (a one-dimensional array), use the DIMENSION statement to set the maximum number of elements in the array. See Format, Data and Expressions in this guide for a complete explanation of matrixes and vectors.

The array name may be any legal variable name. The dimensions may be any positive integer. When specifying the two dimensions of a matrix, the user must use a comma to separate the row and column expressions, which are referred to as indexes. Note that the dimensions must be written as whole numbers; fractional expressions and variables are not allowed.

The user may use a single DIMENSION statement to define multiple arrays. If defining more than one array with a single DIMENSION statement, use commas to separate the array definitions. The DIMENSION statement may be broken into two or more lines, provided that the new line occurs directly after the comma.

The DIMENSION statement declares the name and size of the array only: it does not assign values to the elements of the array. Assignment of values to the elements is done with the MAT, MATPARSE, MATREAD, MATREADU, and assignment statements.

The DIMENSION statement is necessary to preassign the specified number of entries for the array variable. Alternatively, arrays can also be preassigned in a COMMON statement, which is used to declare variables that are shared among external subroutines. See COMMON Statement for more information.

Example

This application declares a matrix called CUSTOMER with 10 rows and 5 columns (for a total of 50 elements), and a vector called PARTS with 15 elements.

DIMENSION CUSTOMER(10,5) , PARTS(15)

See Also

Statement and Function Reference