CONST
 
Syntax


CONST symbolname = value

CONST arrayname = { value [, valuelist] }

      valuelist   =    value [, value]          ' up to 60 values per line

      value  =  integernumber | floatingpointnumber

CONST stringname = "any string"

Description


Declares compiler-time constant symbols that can be an integer.

More complex CONST can now be handled by #define -- see pre-processor

under the hood-

Single constants do not take up any program space as they are maintained by the PC Compiler. 

Constants can be 32 bit values using the PC ARMbasic compiler and can be integer or floating point numbers. but constants are limited to 16bit values for the on chip ARMweb compiler.  A floating point number is any number that contains a decimal point, without a decimal point numbers are assumed to be integers.   If you want the floating point representation of an integer an example would be 123.  , -455. ,  0.  , 122.0  or 0.0  .

Array constants are stored in high memory along with constant strings and do take up Flash space available on the ARM. You can use the constants in your program as if it were an array. 

Constant arrays can span more than one line, the compiler, it will keep reading lines until the final } is found.  This feature was added in version 8.16c of the compiler.

Constants when used are not type checked or type converted, so if you try to assign an integer constant to a single variable, you will get odd looking results.

Example

CONST REPS = 20
  
CONST repeatedstring = "something used more than once"

DIM X as SINGLE
DIM I

CONST  factorials = { 1., 1., 2., 6., 24. , 120. , 720., 5040. , 40320. , 362880. , 3628800. , 39916800. ,  479001600. ,
                           6227020800. , 87178291200. , 1307674368000. , 20922789888000. , 355687428096000. ,
                           6402373705728000. ,121645100408832000. , 2432902008176640000. ,  51090942171709400000. ,
                           1124000727777610000000. , 25852016738885000000000. , 620448401733239000000000. ,
                           15511210043331000000000000. , 403291461126606000000000000. ,  10888869450418400000000000000. ,
                           304888344611714000000000000000. , 8841761993739700000000000000000. , 265252859812191000000000000000000.,
                           8222838654177920000000000000000000. , 263130836933694000000000000000000000. ,
                           8683317618811890000000000000000000000. , 295232799039604000000000000000000000000. }
 
PRINT repeatedstring

FOR I=0 to  REPS 
   X = factorials (i) 
   PRINT I,X
NEXT I

PRINT repeatedstring


------------------------------------------------------------

something used more than once
0       1.
1       1.
2       2.
3       6.
4       24.
5       120.
6       720.
7       5040.
8       40320.
9       362880.
10       3628800.
11       39916800.
12       479001600.
13       6227020800.
14       87178291200.
15      1307674368000.
16      20922789888000.
17      355687428096000.
18      6402373705728000.
19      121645100408832000.
20      2432902008176640000
1
something used more than once

Differences from other BASICs

  • Visual BASIC allows more complex CONST declarations
  • syntax in PBASIC is             symbolname CON value         
See also