02-03-2024, 02:53 AM
(02-02-2024, 10:13 PM)bartok Wrote: Hi, I need an explanation about the command "CLEAR".CLEAR erases the values within variables. The variables still exist they are just nulled or set to zero.
DIM a% locates a part of memory for the variable a%, that is empty.
a%=1 give to the variable a% the value 1.
What does CLEAR? Does it makes a% empty again, or does it deletes the memory located for a%, virtually "deleting" the command DIM a%?
Dynamic arrays (REDIM) are completely removed however and will need to be redimensioned after a CLEAR statement. The code below shows the different behaviors.
Code: (Select All)
OPTION _EXPLICIT
DIM a%
DIM s$
REDIM b%(20)
a% = 1
s$ = "Test"
b%(20) = 2
PRINT a%
PRINT s$
PRINT b%(20)
CLEAR
PRINT a% ' a reset to 0
PRINT s$ ' reset to null
'PRINT b%(20) ' if you activate this line you'll get an error