Dimensioned Arrays

Dimensioned arrays (also called standard arrays) are one- or two- dimensioned structures. Each value in a standard array is called an element of the array.

A one-dimensioned array (also called a vector) has its elements arranged in sequence. An element of a vector is specified by the variable name, followed by the index of the element enclosed in parentheses. The index of the first element is (1).

A two-dimensioned array (also called a matrix) has the elements of the first row arranged sequentially in memory, followed by the elements of the second row, and so on. An element of a matrix is specified by the variable name, followed by two indexes enclosed in parentheses, representing the row and column position of the element. The indexes of the first element are (1,1).

The indexes used to specify the elements of a matrix that has four columns and three rows are illustrated by the following:

COST:

 

Col1

Col2

Col3

Col4

Row1

COST(1,1)

COST(1,2)

COST(1,3)

COST(1,4)

Row2

COST(2,1)

COST(2,2)

COST(2,3)

COST(2,4)

Row3

COST(3,1)

COST(3,2)

COST(3,3)

COST(3,4)

Note that vectors, or one-dimensioned arrays, are treated as matrixes with a second dimension of 1. COST(3) and COST(3,1) are equivalent specifications and can be used interchangeably.

Indexes can be written as constants or as expressions.

Before a dimensioned array can be used in an mvBASIC program, a DIM or COMMON statement must be used to declare the maximum number of elements it will store throughout the program. See the reference pages on DIM and COMMON for more information.

See Also

Advanced Data Types

Array Variables

File Variables

Select-list Variables