DIM
Syntax
Declaring Arrays: DIM symbolname (size )
Declaring Strings: DIM symbolname$ (size )
Description
Declares a named variable and allocates memory to accommodate it. Though ARMbasic does not require the declaration of integer variables, DIM is used to assign arrays of integers or strings (arrays of bytes). The size is the number of elements in the array plus 1. This allows indexing from 0 to size .
All strings must have the last character the dollar sign $ .
Only one symbolname may be declared with each DIM statement.
Memory for simple variables is allocated from the start of a heap, and strings or arrays are allocated from the top or end of the heap. Strings are packed as bytes and always word alligned, you must allow enough space to accomodate the expected maximum size of the string plus 1 byte for a termination (0) character. String operators rely on the terminator.
Example
DIM a$ (10)
DIM b$ (20)
DIM c$ (30)
a$ = "Hello World"
b$ =
"... from ARMbasic!"
c$ = a$
+ b$
print
c$
' displays Hello World... from ARMbasic
Differences from other BASICs
- Like Visual BASIC the first element uses an offset of 0, but also memory is allocated for 0, 1 to size elements. This is backward compatable with earlier BASICs which indexed from 1 to size .
- PBASIC uses the syntax symbolname VAR WORD | BYTE [(size)]
- this syntax is accepted by the compiler, though not recommended