My Technical Notes

Wednesday, 11 February 2015

OpenOffice Basic: Local and Static Variables

Local Variables

To define a local variable within a `Sub`:

Dim myVar As Object

Local variables will be wiped once the `Sub` finishes.

Static Variables

A static variable is a local variable but it retains its value even after the `Sub` finishes:

Static myVar As Object

Typically, we want to initialise the variable after we declare it, but only once:

Static myObj As Object
If IsNull(myObj) Then
    myObj = ...

No comments: