IBM Lotus Symphony
|
関数およびサブルーチン内で変数や配列を定義する際に、これらをプロシージャレベルで再利用することを宣言して、該当する関数およびサブルーチンが終了しても、こうした変数や配列に代入した値を保持するようにします。ここでは 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 InitVar() As Integer
Static iInit As Integer
Const iMinimum as Integer = 40 REM この関数の最小戻り値
if iInit = 0 then REM 初期化済みかどうかをチェック
iInit = iMinimum
else
iInit = iInit + 1
end if
InitVar = iInit
End Function