Expressió Const

Defines one or more identifiers as constants.

A constant is a variable that helps to improve the readability of a program. Constants are not defined as a specific type of variable, but rather are used as placeholders in the code. You can only define a constant once and it cannot be modified.

Sintaxi:

Const syntax


[Global|Private|Public] Const name = expression[, ...]

Paràmetres:

name: Any identifier that follows the standard variable naming conventions.

expression: Any literal expression.

El tipus de dades s'ha d'ometre. Quan es carrega una biblioteca a la memòria percent LibreOffice Basic converteix internament el codi del programa de manera que cada vegada que s'utilitza una constant l'expressió definida la substitueix.

Scope

By default constants are defined as private in modules and routines. Constants can be made public or global in order to be used from all modules, from all Basic libraries.

Global Private i Public specifiers només es poden utilitzar per a constants de mòduls.

Exemple:


  Const EARTH = "♁" ' module scope
  Private Const MOON = "☾" ' module scope
  Public Const VENUS="♀", MARS="♂" ' general scope
  Global Const SUN = "☉", STAR = "☆" ' general scope
  
  Sub ExampleConst
      Const SUN = 3 * 1.456 / 56 ' SUN is local
      MsgBox SUN,, MOON ' SUN global constant is unchanged
      Const Pgm = "Program", Var = 1.00
      MsgBox Pgm & " " & Var, , VENUS &" and "& MARS
  End Sub

Enum statement

Type statement