21.08.2013 Views

OpenOffice.org BASIC Guide.pdf - OpenOffice.org wiki

OpenOffice.org BASIC Guide.pdf - OpenOffice.org wiki

OpenOffice.org BASIC Guide.pdf - OpenOffice.org wiki

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Scope and Life Span of Variables 22<br />

A = A + 1<br />

End Sub<br />

Module B:<br />

Sub Flop<br />

A = A - 1<br />

End Sub<br />

The value of variable A is not changed by the Test function, but is increased by one in the<br />

Flip function and decreased by one in the Flop function. Both of these changes to the<br />

variable are global.<br />

You can also use the keyword Public instead of Dim to declare a public domain variable:<br />

Public A As Integer<br />

A public domain variable is only available so long as the associated macro is executing and<br />

then the variable is reset.<br />

Global Variables<br />

In terms of their function, global variables are similar to public domain variables, except<br />

that their values are retained even after the associated macro has executed. Global<br />

variables are declared in the header section of a module using the keyword Global:<br />

Global A As Integer<br />

Private Variables<br />

Private variables are only available in the module in which they are defined. Use the<br />

keyword Private to define the variable:<br />

Private MyInteger As Integer<br />

If several modules contain a Private variable with the same name, <strong>OpenOffice</strong>.<strong>org</strong> Basic<br />

creates a different variable for each occurrence of the name. In the following example, both<br />

module A and B have a Private variable called C. The Test function first sets the Private<br />

variable in module A and then the Private variable in module B.<br />

Module A:<br />

Private C As Integer

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!