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