basic.dim

Statement/BASIC Program, Releases: AP and R83

Declares a dimensioned array.

Syntax

dim{ension} array.variable({rows{,cols}})

Description

establishes a specific number of storage locations for a matrix of variables.

Arrays may be of one or two dimensions only. Individual elements within an array are accessed by appending the element number, enclosed in parentheses, to the array variable.

'rows' specifies the number of rows and 'cols' specifies the number of columns of the array. These quantities may be any valid numeric expression.

A 'dim' statement without the number of elements specified, such as in the case: 'dim a()', may only be used in a subroutine. Pick/BASIC run-time determines the number of elements after a 'matread'.

An array must be dimensioned prior to being referenced within a program. After an array has been dimensioned, it may be redimensioned later within a program. When the dimensioning parameters are changed, the new array will:

- retain those elements with the same indexes that were in the old array;

- have any new elements initialized to a unassigned state;

- lose any unreferenced elements (those elements in the old array with indicies not present in the new array).

If an array is passed to a subroutine in an argument list, it cannot be redimensioned within the subroutine. A passed array can only be dimensioned once within a subroutine. Local arrays may be redimensioned as necessary. When arrays are dimensioned both in a subroutine and within the calling program, the dimensions specified in the calling program will supercede those specified within the subroutine, if the subroutine's array was dimensioned as an empty dimension. The number of dimensions must be the same in both the calling program and called subroutine.

Example

dim rec(20),table(3,3)

'rec' is a single dimensional array with 20 subscripted variables.
'table' is a two dimensional array with 9 subscripted variables.

x = 20
dim a(x)
input y
dim b(y)
dim c(x,y)

In AP, 'dimension' can be handled by Pick/BASIC runtime. On
'R83' systems, 'dim' can only be handled by the compiler
and the argument must be a numeric constant.

subroutine process.receipt(receipt.item)
dim work.list()
...
matread work.list ...

This example illustrates a 'dim' statement without arguments. It
resolves the size of the array after the 'matread'.

See Also

Command Name Type Description
basic.array.references Definition Referencing arrays.
basic.matread Statement Reads item into dimensioned array.
basic.matwrite Statement Writes dimensioned array to file.
basic.matbuild Statement Converts dimensioned array to dynamic array.
basic.matparse Statement Converts dynamic array to dimensioned array.
basic.call Statement Calls external Pick/BASIC subroutine.
basic.assignment Definition Assigns value to variable.
basic.dimension Statement see 'dim'
basic.array.dimensioned Definition a table where the contents of the elements can be altered (replaced) but the position of each element is fixed.
basic.statements Definition Definition of statements and functions.
array Definition tables of values of any data type.
arrays.relational.expressions Definition Description of array handling.
basic.mat Statement Assigns data to a dimensioned array.
basic.array.variable Definition References a dimensioned array.
basic.common Statement Declares common variables.
basic.( Reserved Character used to surround arguments within functions, or to enclose subscript refererences within dimensioned arrays. It is also used to override the normal order of precedence evaluation.
basic.) Reserved Character surrounds arguments within functions, encloses subscript refererences within dimensioned arrays, and overrides the normal order of precedence evaluation.

User Comments

What do you think?

Share your experience or ask a question by using the form below.

Login to leave your comments.