Any PowerScript variable declaration of a standard datatype that can be assigned an initial value can be a constant instead of a variable. To make it a constant, include the keyword CONSTANT in the declaration and assign it an initial value.
CONSTANT { access } datatype constname = value
The following table shows the parameters used to declare constants.
Parameter |
Description |
---|---|
CONSTANT |
Declares a constant instead of a variable. The CONSTANT keyword can be before or after the access keywords. |
access (optional) |
(For instance variables only) Keywords specifying the access for the constant. For information, see “Access for instance variables”. |
datatype |
A standard datatype for the constant. For decimals, you can include an optional value in brackets to specify the precision of the data. Blobs cannot be constants. For information about PocketBuilder datatypes, see “Standard datatypes”. |
constname |
The name of the constant (must be a valid PowerScript identifier, as described in “Identifier names”). |
value |
A literal or expression of the appropriate datatype that will be the value of the constant. The value is required. For information, see “Initial values for variables”. |
When declaring a constant, an initial value is required. Otherwise, a compiler error occurs. Assigning a value to a constant after it is declared (that is, redefining a constant in a descendant object) also causes a compiler error.
Although PowerScript is not case sensitive, these examples of local constants use a convention of capitalizing constant names:
constant string LS_HOMECITY = "Boston"
constant real LR_PI = 3.14159265