Static (statement)

<< Click to Display Table of Contents >>

Static (statement)

Static Variable

Allocates memory for a variable and defines its type.

Unlike variables created with the Dim command, Static variables remember their value during the whole program runtime, even if they were declared inside a function.

See also: Dim, Function, Sub

Example:

' This example shows the usage of static variables.

' The value of the variable i in the procedure Joe is preserved.

Sub Main

 For i = 1 to 2

         Joe 2

 Next i

End Sub

Sub Joe(j As Integer)

 Static i

 Print i

 i = i + 5

 Print i

End Sub