Constants

FreeBASIC

Constants
 
Description

Constants are numbers which cannot be changed after they are defined. For example, 5 will always mean the same number.

In FreeBASIC, a constant definition differs from a variable definition by usage of the Const command.

Such constants are then available globally, meaning that once defined, you can use the word to refer to a constant anywhere in your program.

After being defined with the Const command, constants cannot be altered. If code tries to alter a constant, an error message will result upon code compilation.

Example

Declare Sub PrintConstants ()

Const FirstNumber = 1
Const SecondNumber = 2
Const FirstString = "First string."

Print FirstNumber, SecondNumber 'This will print 1      2
Print FirstString 'This will print First string.

PrintConstants ()

Sub PrintConstants ()
    Print FirstNumber, SecondNumber 'This will also print 1        2
    Print FirstString 'This will also print First string.
End Sub



See also