Text Documents (Writer)
HTML Documents (Writer Web)
Spreadsheets (Calc)
Presentations (Impress)
Drawings (Draw)
Database Functionality (Base)
Formulae (Math)
Charts and Diagrams
Macros and Scripting
Office Installation
Common Help Topics
OneOffice Logo

Static Statement

Declares a variable or an array at the procedure level within a subroutine or a function, so that the values of the variable or the array are retained after exiting the subroutine or function. Dim statement conventions are also valid.

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

Syntax:


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

Example:


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
 
' Function for initialisation of the static variable
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 initialised
        iInit = iMinimum
    Else
        iInit = iInit + 1
    End If
    InitVar = iInit
End Function