Const Command

Purpose

Declares constants for use in place of literal values.

Syntax

[Global | Local] Const name [As type] = v [, name1 [As type] = v, …]

name: variable name
v: aexp

Description

A constant is a named item that retains a constant value throughout the execution of a program. Constants can be used anywhere in your code in place of actual values. A constant can be a string or numeric literal, another constant, or any combination that includes arithmetic or logical operators.

Unless a Const is declared Global, it has local scope.

The default type of a constant is Long (32-bits integer). However, simple types are allowed as well. Const accept typed constants as Bool, Byte, Short, Integer, Double, Single, Large, Currency, String, Date. When a type is specified, GFA-BASIC 32 checks for a valid assignment at compile time.

Without a type specifier, the type of the constant is determined from the value. A string literal will create a string constant and a date literal a Date constant. Some types of a constant can be forced to a specific type by adding a postfix to the value. By appending a @ a Currency constant is declared, a ! forces a Single, a # forces a Double.

Example

Const WM_USER = 0x400  ' hex literal

Const WM_PAINT = 15    ' decimal

Const WM_CLOSE = $10   ' hex literal

Const WM_USER = 0x400, WM_PAINT = 15, WM_CLOSE = $10, WM_QUIT = WM_CLOSE + 2

Implicit types

Const PiQuarter = Atn(1)              ' Double

Const GFAhometown = "Mönchengladbach" ' String

Explicit types

Global Const ACur = 2@             ' Currency

Global Const AFloat = 2!           ' Single

Global Const ADouble = 2#          ' Double

Const last_changing = #12.07.1996# ' Date type

Remarks

A constant can be given a type also by using a normal variable postfix (?, !, @, #, $, %, &).

Global Const ADouble# = 2

See Also

Enum, Global, Local, Dim

{Created by Sjouke Hamstra; Last updated: 26/09/2014 by James Gaite}