Defines local variables in a subroutine and main program. Variables declared with the Static statement retain their values as long as the code is running.
Static [Dim] varname[()] [As [New] type] [ = value], …
Static type varname1 [ = value], varname2 [ = value], …
Static varname1$ [ = value], varname2% [ = value], …
varname: name of variable
type: Optional. Data type of the variable; may be Byte, Boolean, Card, Short, Word, Integer, Long, Large, Currency, Single, Double, Date, String, (for variable-length strings), String * length (for fixed-length strings), Object, Variant, a user-defined type, or an object type. Use a separate As type clause for each variable being defined.
Static declares local variables. When used in the main program, the variable's scope is limited to the main part and isn't known in subroutines. In this respect, Static and Local work the same.
The New keyword enables implicit creation of a few GFA-BASIC 32 objects, like DisAsm, Collection, StdFont, Font, StdPicture, Picture, CommDlg, and ImageList. If you use New when declaring the object variable, a new instance of the object is created on first reference to it, so you don't have to use the Set statement to assign the object reference. The New keyword can't be used to declare variables of any intrinsic data type.
If you don't specify a data type or object type and there is no Deftype statement in the module, the variable is Variant by default.
Variables can be initialized while they are declared.
When a variable isn't explicitly initialized, a numeric variable is initialized to 0, a variable-length string is initialized to a zero-length string (""), and a fixed-length string is filled with zeros. Variant variables are initialized to Empty. Each element of a user-defined type variable is initialized as if it were a separate variable.
OpenW 1
AutoRedraw = 1
Local a%, x%, i%' scope in main program
For i% = 1 To 10
a% += i%
Print KeepTotal(a%)
Next i%
Function KeepTotal(Number As Double)
' Only the variable Accumulate preserves its value between calls.
Static Accumulate As Double
Accumulate = Accumulate + Number
KeepTotal = Accumulate
End Function
Boolean, Byte, Card, Short, Word, Int16, Long, Int, Integer, Int32, Int64, Large, Single, Double, Currency, Date, Handle, String, Variant, Object
{Created by Sjouke Hamstra; Last updated: 23/10/2014 by James Gaite}