Instructie Static
Declareert een variabele of een matrix op het procedureniveau binnen een subroutine of functie zodat de waardes van de variabele of de array worden behouden na het beƫindigen van de subroutine of functie. Regels voor de instructie Dim zijn ook geldig.
De instructie Static kan niet worden gebruikt om variabele arrays te definiƫren. Arrays moeten worden gespecificeerd overeenkomstig een vaste grootte.
Syntaxis:
Static VarNaam[(Start to Einde)] [As VarType], VarNaam2[(Start to Einde)] [As VarType], ...
Voorbeeld:
Sub ExampleStatic
Dim iCount As Integer, iResult As Integer
For iCount = 0 To 2
iResult = InitVar()
Next iCount
MsgBox iResult,0,"Het antwoord is"
End Sub
' Functie voor initialiseren van de Static-variabele
Function InitVar() As Integer
Static iInit As Integer
Const iMinimum as Integer = 40 ' minimale retourwaarde van deze functie
if iInit = 0 then ' controle indien geĆÆnitialiseerd
iInit = iMinimum
Else
iInit = iInit + 1
End If
InitVar = iInit
End Function