|
Similar to DIM, this statement names one or more variables and allocates storage space for them.
However, declaring STATIC variables means that variable values are preserved between procedure calls.
Note that only simple types are affected.
Syntax: STATIC variable[(subscripts)] AS type
STATIC A AS INTEGER, B AS BYTE, S AS STRING
Details:
STATIC has no affect (ie. same as using DIM) when declared in the main module.
Use STATIC only inside a SUB/I or FUNCTION/I.
Examples:
'-- Non static count
SUB Count (N AS INTEGER)
DIM B AS LONG
B = N
IF N = 10 THEN EXIT SUB
Count(N+1)
PRINT B
END SUB
Count(1)
'-- Static count, B retains the same value
SUB StaticCount (N AS INTEGER)
STATIC B AS LONG
B = N
IF N = 10 THEN EXIT SUB
StaticCount(N+1)
PRINT B
END SUB
StaticCount(1)
|