DOCS

# DIM Statement

The DIM statement is used to declaring variables and arrays.

# Syntax

- DIM decl1 [, decl2 …] AS { BOOLEAN | BYTE | SHORT | INTEGER | LONG | FLOAT | DOUBLE | COMPLEX | STRING | VARIANT }

Declarations may be simply variables or single/multi dimensional arrays. e.g. X(5,6)

# Description

The DIM command is used to declare and dimension variables for use by a Mobile BASIC program. Simple variables are associated with a single value and have a dimension of 1. There are times when a simple variable is not appropriate (e.g. MONTHS would need to contain the values January, February, … December) and for these you will need to define them as arrays. Arrays are defined by postfixing the dimensions of the array onto the end of the variable.

- DIM X AS INTEGER // X is a simple integer variable.
- DIM X(3) AS INTEGER // X is an integer array with three elements: X(1), X(2) and X(3)
- DIM X(3,3) AS INTEGER // X is a two dimensional integer array consisting of nine elements: X(1,1), X(1,2), X(1,3), X(2,1), X(2,2), X(2,3), X(3,1), X(3,2) and X(3,3).
- DIM X(4,3,2) AS INTEGER // X is a three dimensional integer array.

Array element are accessed by appending the element number enclosed within parenthesis to the variable name. Array elements are indexed from one up to the array dimension. Thus DIM I(3) defines 3 items: I(1), I(2) and I(3). Access any of subscripts will cause an array out of bounds error to be generated.

# Example

```
SUB MAIN
DIM MONTH_ARRAY(12) AS STRING
DIM I AS INTEGER
MONTH_ARRAY(1)="January"
MONTH_ARRAY(2)="February"
MONTH_ARRAY(3)="March"
MONTH_ARRAY(4)="April"
MONTH_ARRAY(5)="May"
MONTH_ARRAY(6)="June"
MONTH_ARRAY(7)="July"
MONTH_ARRAY(8)="August"
MONTH_ARRAY(9)="September"
MONTH_ARRAY(10)="October"
MONTH_ARRAY(11)="November"
MONTH_ARRAY(12)="December"
FOR I=1 TO 12
PRINT "Month " + STRING(I) + " = " + MONTH_ARRAY(I)
END FOR
END SUB
```