Important Notice
The pages on this site contain documentation for very old MS-DOS software,
purely for historical purposes.
If you're looking for up-to-date documentation, particularly for programming,
you should not rely on the information found here, as it will be woefully
out of date.
REDIM Statement Example
◄Example► ◄Contents► ◄Index► ◄Back►
──────────────────────────────────────────────────────────────────────────────
' This example uses the PRESERVE keyword in the REDIM statement to add
' records to an existing array as more data is entered.
DATA 23, -45, 6, 5, 1, 12, 7, 1, -9, 0
CLS ' Clear the screen
REDIM X(1 TO 10) AS INTEGER ' Create dynamic array
FOR I% = 1 TO 10 ' Read in data
READ X(I%)
NEXT I%
DO
INPUT "Item to add to list (ENTER to finish)"; A$ ' Resize array X()
IF LEN(A$) THEN ' as items are added
REDIM PRESERVE X(1 TO UBOUND(X) + 1) AS INTEGER ' using REDIM with
X(UBOUND(X)) = VAL(A$) ' PRESERVE keyword
END IF
LOOP WHILE LEN(A$)
FOR I% = 1 TO UBOUND(X) ' Print array
PRINT X(I%)
NEXT I%
END