Static Statement

Deklarira varijablu ili polje na proceduralnom nivou unutar podprograma ili funkcije, tako da vrijednost varijable ili polja ostane nakon izvršavanja podprograma ili funkcije. Dim konvencija naredbe je isto ispravna.

Warning Icon

The Static statement cannot be used to define variable arrays. Arrays must be specified according to a fixed size.


Syntax:


Static VarName[(start To end)] [As VarType], VarName2[(start To end)] [As VarType], ...

Primjer:


Sub ExampleStatic
Dim iCount As Integer, iResult As Integer
    For iCount = 0 To 2
        iResult = InitVar()
    Next iCount
    MsgBox iResult,0,"The answer is"
End Sub
 
REM Funkcija za inicijalizaciju statiÄŤke varijable
Function InitVar() As Integer
    Static iInit As Integer
    Const iMinimum As Integer = 40 ' minimum return value of this function
    If iInit = 0 Then ' check if initialized
        iInit = iMinimum
    Else
        iInit = iInit + 1
    End If
    InitVar = iInit
End Function

Please support us!