Constants
- {{{parttitle}}}
Constants are values which may be used but not changed by the program.
Defining Constants
In Apache OpenOffice Basic, use the keyword Const to declare a constant.
ConstA=10 ConstB=A+5 ConstHi="Hello World"
This code shows that you do not get the type that you specify.
ConstalphaAsLong=1 ConstbetaAsSingle=3.1 ConstgammaAsBoolean=True ConstdeltaAsCurrency=123456.05 ConstphiAsLong=32768 MsgBox(TypeName(alpha))' displays : Integer MsgBox(TypeName(beta))' displays : Double MsgBox(TypeName(gamma))' displays : Integer MsgBox(TypeName(delta))' displays : Double MsgBox(TypeName(phi))' displays : Double
As Basic makes automatic type conversions, there is usually no problems using a constant in an expression.
If you want to specify the type of a data, use a typed variable, not a constant.
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.
PublicConstone=1
Predefined Constants
Apache OpenOffice Basic predefines several constants. Among the most useful are:
- True and False, for Boolean assignment statements
- PI as a type Double numeric value
DimbHitasBoolean bHit=True DimdAreaasDouble,dRadiusasDouble ' ... (assign a value to dRadius) dArea=PI*dRadius*dRadius