QB64.com

QB64 is a modern extended BASIC programming language that retains QBasic/QuickBASIC 4.5 compatibility and compiles native binaries for Windows, Linux, and macOS.

The CONST statement globally defines one or more named numeric or string values which will not change while the program is running.

Syntax

CONST constantName = value[, …]

Parameter(s)

Description

Example(s)

Display the circumference and area of circles:


' Declare a numeric constant approximately equal to the ratio of a circle's
' circumference to its diameter:
CONST PI = 3.141593

' Declare some string constants:
CONST circumferenceText = "The circumference of the circle is"
CONST areaText = "The area of the circle is"

DO
    INPUT "Enter the radius of a circle or zero to quit"; radius
    IF radius = 0 THEN END
    PRINT circumferenceText; 2 * PI * radius 
    PRINT areaText; PI * radius * radius ' radius squared
    PRINT
LOOP


Enter the radius of a circle or zero to quit? *10*
The circumference of the circle is 62.83186
The area of the circle is 314.1593

Enter the radius of a circle or zero to quit? *123.456*
The circumference of the circle is 775.697
The area of the circle is 47882.23

Enter the radius of a circle or zero to quit? *0*

Explanation: PI cannot change as it is a mathematical constant so it is fitting to define it as a constant. Trying to change PI will result in a calculation error.

Example 2: Using _RGB32 to set a constant’s value.


CONST Red = _RGB32(255,0,0)

COLOR Red
PRINT "Hello World"

See Also