QB64.com

QB64 is a modern extended BASIC programming language that retains QBasic/QuickBASIC 4.5 compatibility and compiles native binaries for Windows, Linux, and macOS.

A REDIM statement can re-dimension one $DYNAMIC(flexible) Arrays or a comma separated list of arrays.

Syntax

REDIM [_PRESERVE] [SHARED] ArrayName[type_suffix] ({max_element low_element[TO upper_element, …]}) [AS Type]
REDIM [_PRESERVE] [SHARED] [AS Type] ArrayName({max_element low_element[TO upper_element, …]})

Description

Example(s)

The $DYNAMIC metacommand allows an array to be re-sized using DIM and REDIM.


'$DYNAMIC

INPUT "Enter array size: ", size 
DIM Array(size)

REDIM Array(2 * size)

PRINT UBOUND(Array) 

Shows the difference between REDIM and REDIM _PRESERVE.


REDIM array(20)
array(10) = 24

PRINT array(10)

REDIM _PRESERVE array(30)
PRINT array(10)

REDIM array(15)
PRINT array(10) 


 24
 24
 0

Explanation: REDIM without _PRESERVE erases the array data and cannot change the number of dimensions.

See Also