Інструкція 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.

Синтаксис:

Const syntax


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

Параметри:

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

expression: Any literal expression.

The data type must be omitted. When a library gets loaded in memory, LibreOffice Basic converts the program code internally so that each time a constant is used, the defined expression replaces it.

Область видимості

За промовчанням константи визначаються як особисті в модулях і підпрограмах. Константи можна зробити загальнодоступними або глобальними, щоб використовувати їх з усіх модулів, із усіх бібліотек Basic.

Global, Private and Public specifiers can only be used for module constants.

Приклад:


  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

Будь ласка, підтримайте нас!