Rockwell Automation 1771-DB BASIC MODULE User Manual

Page 159

Advertising
background image

Chapter
Statements

11

11 -7

Use the DIM statement to reserve storage for arrays. The storage area is
first assumed to be zero. Arrays in the BASIC module may have only one
dimension and the size of the dimensioned array may not exceed 254
elements.

Once you dimension a variable in a program you may not re-dimension it.
An attempt to re-dimension an array causes an array size error and the
module enters the Command mode.

If you use an array variable that you did not dimension by a DIM
statement, BASIC assigns a default value of 10 to the array size.
All arrays are set equal to zero when you execute the RUN command (page
10 -19), NEW command (page 10 -10) or the CLEAR statement (page
11 -2).

The number of bytes allocated for an array is six times the array size plus
one (6

(array size + 1)). For example, the array A (100) requires 606 (6

* (100+1)) bytes of storage. Memory size usually limits the size of a
dimensioned array.

Important: If using strings you must define them in your program with
the STRING statement (page 11 -37) before you define arrays with the
DIM statement.

Syntax

DIM

Example

>1 REM EXAMPLE PROGRAM

>10 DIM A(25), C(15), A1(20)

Error on attempt to re-dimension array:

>1 REM EXAMPLE PROGRAM

>10 A(5) = 10 :REM BASIC ASSIGNS DEFAULT OF 10 TO ARRAY A

>20 DIM A(5) : REM ARRAY RE–DIMENSION ERROR

READY

>RUN

ERROR: ARRAY SIZE – IN LINE 20

20 DIM A(5) : REM ARRAY RE–DIMENSION ERROR

–––––––––––––––X

READY

>

DIM

Advertising