DIM
DIM var([lower TO] upper [, …]) [, …]
Reserves storage space for an array.
The array will have (upper-lower)+1 elements. If lower
is not specified, and OPTION BASE
hasn’t used, elements
start at 0.
Example 1: One dimensional arrays
REM One dimensional array of 7 elements, starting from 0
REM with elements A(0), A(1), ... , A(6)
DIM A(6)
REM One dimensional array of 7 elements, starting from 3
REM with elements A(3), A(4), ... , A(9)
DIM A(3 TO 9)
REM One dimensional array of 6 elements, starting from 1
REM with elements A(1), A(2), ... , A(6)
option base 1
DIM A(6)
Example 2: Multi dimensional arrays
REM Two dimensional array
DIM A(3, 4)
REM Three dimensional array
DIM A(2 TO 6, 5 TO 9, 1 TO 8)
Example 3: Empty array
REM Allocating zero-length arrays:
DIM z()
Example 4: Creating and accessing arrays
Option Base 1 ' Set default lower bound of arrays to 1
"Showing x,y,z elements of index 5:"
?
?' Reserve space for a single 1-dimensional array:
0
x = 10
y = 20
z = Dim a(1 To 30)
For i = 1 To 10
a(i + x) = i10
a(i + y) = i + 100
a(i + z) = i + Next
5 + x), a(5 + y), a(5 + z),, "(1-dimensional array)"
? a(
' Reserve the same space for three 1-dimensional arrays:
Dim a_x(1 To 10), a_y(1 To 10), a_z(1 To 10)
For i = 1 To 10
a_x(i) = i10
a_y(i) = i + 100
a_z(i) = i + Next
5), a_y(5), a_z(5),, "(three 1-dimensional arrays)"
? a_x(
' Reserve the same space for a single 2-dimensional array:
1
x = 2
y = 3
z = Dim a(1 To 10, x To z)
For i = 1 To 10
a(i, x) = i10
a(i, y) = i + 100
a(i, z) = i + Next
5, x), a(5, y), a(5, z),, "(2-dimensional array)"
? a(
' Reserve the same space for a single nested array:
Dim a(1 To 10)
For i = 1 To 10
' convert this element to nested array
a(i) = [,,]
a(i)(x) = i10
a(i)(y) = i + 100
a(i)(z) = i + Next
5)(x), a(5)(y), a(5)(z),, "(nested array)"
? a(
' Reserve the same space for a single map array (see also: ARRAY, ISMAP):
Dim a(1 To 10)
For i = 1 To 10
a(i).x = i10
a(i).y = i + 100
a(i).z = i + Next
5).x, a(5).y, a(5).z,, "(map array)" ? a(
Code samples using DIM
006 arrays+.bas
100lines.bas
2048.bas
2048.bas
3d block lettes.bas
3d_palmx.bas
3d_torus.bas
3dtictac.bas
3dtorus.bas
3dttt.bas
3dttt.bas
7gables.bas
ai.bas
anomail.bas
aquarium v2.bas
ascii 3d.bas
bairstow.bas
base64.bas
betrayal: crows ii.bas
bezier_pen.bas
blackbox.bas
Blackbox.bas
blackjack.bas
BlackJack.bas
block.bas
boing.bas
bolmo.bas
bomb.bas
bonkers.bas
Data
APPEND
ARRAY
DATA
DELETE
DIM
EMPTY
ERASE
INSERT
ISARRAY
ISDIR
ISFILE
ISLINK
ISMAP
ISNUMBER
ISSTRING
LBOUND
LEN
READ
REDIM
RESTORE
SEARCH
SORT
SWAP
UBOUND
If there is insufficient information on this page and you wish learn more about DIM,
please send an email to smallbasic@gmail.com. You can help to improve information about
DIM by submitting a pull request,
click View Source for details. Note, an offline language reference text file is also available - see the Download section.