Constants

From Wiki
Jump to navigationJump to search




Constants are values which may be used but not changed by the program.


Defining Constants

In OpenOffice.org Basic, use the keyword Const to declare a constant.

Const A = 10

You can also specify the constant type in the declaration:

Const B As Double = 10


Scope of Constants

Constants have the same scope as variables (see Scope and Life Span of Variables), but the syntax is slightly different. A Const definition in the module header is available to the code in that module. To make the definition available to other modules, add the Public keyword.

Public Const one As Integer = 1


Predefined Constants

OpenOffice.org Basic predefines several constants. Among the most useful are:

  • True and False, for Boolean assignment statements
  • PI as a type Double numeric value
Dim bHit as Boolean
bHit = True

Dim dArea as Double, dRadius as Double
' ... (assign a value to dRadius)
dArea = PI * dRadius * dRadius
Content on this page is licensed under the Public Documentation License (PDL).