From QB64 Wiki
Revision as of 23:17, 2 October 2009 by (talk)
Jump to navigation Jump to search

The DIM statement is used to declare a variable type or dimension an array.

Syntax 1: DIM variable AS type
Syntax 2: DIM Array(elements) AS type
Syntax 3: DIM Array(elements)
Syntax 4: DIM SHARED variable AS type
Syntax 5: DIM variable AS _UNSIGNED type

  • Uses the AS keyword to define a variable or array type as INTEGER, LONG, SINGLE, DOUBLE or STRING.
  • QB64 can also use _BIT, _BYTE, _INTEGER64 or _FLOAT variable types.
  • Can set the range of elements(indices) of an array.
  • When the $DYNAMIC metacommand is not used, array sizes are unchangeable($STATIC).
  • Use REDIM instead of DIM to dimension arrays as dynamic without the $DYNAMIC metacommand.
  • Can also DIM variables as SHARED for sub-procedures to have access to them.
  • All types can be dimensioned as _UNSIGNED, or positive only, in QB64.

Example 1: DIM Qt AS STRING * 1 ' defines Qt variable as a fixed length one byte string

Example 2: DIM Image(2000) AS INTEGER ' dimensions and types an array

Example 3: DIM Image%(2000) ' dimensions array without determining the type

Example 4: DIM SHARED Image(1 TO 1000) AS INTEGER ' dimensions a range of elements as an integer.

Example 5: DIM bit(8) AS _UNSIGNED _BIT 'Dimensions variable as an array of 8 elements of the type _UNSIGNED _BIT.

See also: DEFINT, DEFSNG, DEFLNG, DEFDBL, DEFSTR, _DEFINE, Mathematical Operations


Go to Keyword Reference - Alphabetical

Go to Keyword Reference - By usage