Skip to main content

Dim

Dim (Statement)​

Format​

Create a One Dimensional Array​

dim variable ( array_size )
dim variable ( array_size ) fill expression
dim variable [ array_size ]
dim variable [ array_size ] fill expression

Create a Two Dimensional Array​

dim variable ( array_size_rows , array_size_columns)
dim variable ( array_size_rows , array_size_columns) fill expression
dim variable [ array_size_rows , array_size_columns]
dim variable [ array_size_rows , array_size_columns] fill expression

Use a List to Create and Fill an Array​

dim variable = { list ... }
dim variable[] = { list ... }
dim variable = { { list ... }, { list ... } ... }
dim variable[] = { { list ... }, { list ... } ... }

Copy One Array to Another​

dim variable = variable[]
dim variable[] = variable[]

Fill an Existing Array With a Single Value​

dim variable fill expression
dim variable[] fill expression

Description​

Returns a newly created single dimensional array of length integer or a 2 dimensional array that can be addressed by row and column. Every element is given a starting value, so that it may be read straight away: a variable whose name ends in $ is filled with the empty string, and any other variable with the whole number 0. You may add the fill option to fill all of the elements with a single value of your own instead.
The first element of an array has an index of 0 (zero). Indexes range from 0 to length-1.

The dim statement can also be used to create a new array that is a duplicate of another array. The form “DIM var = var” does this by dimensioning a new array in memory and copying all of the data from the original array.

Example​

dim z = {1, 2, 3, 4, 5}
print z[0] + " " + z[4]

will print

1 5

Example Two​

dim c(4)
c[0] = "cow"
c[1] = "brown"
c[2] = "how"
c[3] = "now"
print c[2] + " " + c[3] + " ";
print c[1] + " " + c[0] + "?"

will print

how now brown cow?

See Also​

ArrayBase, ArrayLength, Assigned, Dim, Fill, Map, Mat, Redim, TypeOf, Unassign, VariableWatch

History​

1.99.99.55Cleaned up documentation and added array copy.
1.99.99.56Added fill clause
1.99.99.57Added additional fill options
1.99.99.72added the [] when setting one array from another
2.1elements are filled with 0 (or "" for a $ name) instead of being left unassigned