FBWiki : ProPgConstants

FBWiki :: Categories :: PageIndex :: RecentChanges :: RecentlyCommented :: Login/Register

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.

Examples:
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:

Back to Programmer's Guide

There is one comment on this page. [Display comment]

Valid XHTML 1.0 Transitional :: Valid CSS :: Powered by Wikka Wakka Wiki 1.1.6.0



sf.net phatcode