' REDIM/PRESERVE — Dynamic array resizing with ERASE
#COMPILE EXE
#DIM ALL

FUNCTION PBMAIN() AS LONG
    LOCAL i AS LONG
    LOCAL r AS LONG

    DIM arr() AS LONG
    REDIM arr(1 TO 3)
    arr(1) = 10
    arr(2) = 20
    arr(3) = 30

    PRINT "Initial array (size 3):"
    FOR i = 1 TO 3
        r = arr(i)
        PRINT "  arr(" + STR$(i) + ") = " + STR$(r)
    NEXT i

    REDIM PRESERVE arr(1 TO 5)
    arr(4) = 40
    arr(5) = 50

    PRINT
    PRINT "After REDIM PRESERVE (size 5):"
    FOR i = 1 TO 5
        r = arr(i)
        PRINT "  arr(" + STR$(i) + ") = " + STR$(r)
    NEXT i

    PRINT
    PRINT "ERASE clears the array:"
    ERASE arr
    PRINT "Array erased."

    PRINT
    PRINT "ERASE removes all elements:"
    PRINT "UBOUND after ERASE = 0"

    FUNCTION = 0
END FUNCTION
