Difference between revisions of "Documentation/BASIC Guide/Constants"

From Apache OpenOffice Wiki
Jump to: navigation, search
Line 12: Line 12:
 
In {{OOo}} Basic, use the keyword <tt>Const</tt> to declare a constant.
 
In {{OOo}} Basic, use the keyword <tt>Const</tt> to declare a constant.
  
Const A = 10
+
<source lang="oobas">
 +
Const A = 10
 +
</source>
  
 
You can also specify the constant type in the declaration:
 
You can also specify the constant type in the declaration:
  
Const B As Double = 10
+
<source lang="oobas">
 +
Const B As Double = 10
 +
</source>
 +
 
 
== Scope of Constants ==
 
== Scope of Constants ==
 +
 
Constants have the same scope as variables (see [[Documentation/BASIC Guide/Scope of Variables|Scope and Life Span of Variables]]), but the syntax is slightly different.  A <tt>Const</tt> definition in the module header is available to the code in that module.  To make the definition available to other modules, add the <tt>Public</tt> keyword.
 
Constants have the same scope as variables (see [[Documentation/BASIC Guide/Scope of Variables|Scope and Life Span of Variables]]), but the syntax is slightly different.  A <tt>Const</tt> definition in the module header is available to the code in that module.  To make the definition available to other modules, add the <tt>Public</tt> keyword.
  
Public Const one As Integer = 1
+
<source lang="oobas">
 +
Public Const one As Integer = 1
 +
</source>
  
 
{{PDL1}}
 
{{PDL1}}

Revision as of 13:05, 2 April 2008


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.

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
Content on this page is licensed under the Public Documentation License (PDL).
Personal tools