The [[DIM]] statement is used to declare a variable or a list of variables as a specified data type or to dimension [[$STATIC]] or [[$DYNAMIC]] [[Arrays|arrays]].
* Use the [[AS]] keyword to define a variable or array ''type'' [[AS]]...
** [[INTEGER]] (or use variable suffix '''%''')
** [[LONG]] (or use variable suffix '''&''')
** [[SINGLE]] (or use variable suffix '''!''' or no suffix by default)
** [[DOUBLE]] (or use variable suffix '''#''')
** [[STRING]] (or use variable suffix '''$'''). An AS multiplier can set the string [[LEN|length]]. Ex: {{InlineCode}}DIM ''variable'' AS STRING * 8{{InlineCodeEnd}}
** [[_BIT]] (or use variable suffix '''`'''). An AS multiplier can be used for multiple bits. Ex: {{InlineCode}}DIM ''variable'' AS _BIT * 8{{InlineCodeEnd}}
** [[_BYTE]] (or use variable suffix '''%%''')
** [[_INTEGER64]] (or use variable suffix '''&&''')
** [[_FLOAT]] (or use variable suffix '''##''')
** [[_OFFSET]] (or use variable suffix '''%&''')
** DIM AS [[_MEM]] (the _MEM type has no type suffix).
* Use [[REDIM]] [[_PRESERVE]] in '''QB64''' to retain previous array values when changing the size of an array.
* [[REDIM]] [[_PRESERVE]] cannot change the number of array dimensions. An [[ERROR Codes|error]] will occur.
* [[$DYNAMIC|Dynamic]] arrays MUST be [[REDIM]]ensioned if [[ERASE]] or [[CLEAR]] are used, as the arrays are completely removed.
* All numerical variable types '''except''' {{KW|SINGLE}}, {{KW|DOUBLE}} and {{KW|_FLOAT}} can be dimensioned as [[_UNSIGNED]] (suffix ~) or positive only.
* '''NOTE:''' Many QBasic keyword variable names can be used with a [[STRING]] suffix ($). You cannot use them without the suffix, use a numerical suffix or use ''DIM, [[REDIM]], [[_DEFINE]], [[BYVAL]] or [[TYPE]] variable [[AS]]'' statements. '''Although possible, it's recommended to avoid using reserved names.'''