Static Statement

변수나 배열의 값이 서브루틴 또는 함수가 종료된 후에도 유지되도록 변수나 배열을 서브루틴 또는 함수 내의 프로시저 수준에서 선언합니다. 또한 Dim 문 규칙도 유효합니다.

경고 아이콘

Static 문은 변수 배열을 지정하는 데 사용할 수 없습니다. 배열은 고정 크기로 지정해야 합니다.


구문:

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

예:

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 Function for initialization of the static variable
Function InitVar() As Integer
    Static iInit As Integer
    Const iMinimum as Integer = 40 REM minimum return value of this function
    if iInit = 0 then REM check if initialized
        iInit = iMinimum
    Else
        iInit = iInit + 1
    End If
    InitVar = iInit
End Function

Please support us!