|
Constant | ||||
Constant <.Name.> = StringValue|FloatValue|IntegerValue | ||||
Parameters: NONE | ||||
Returns: NONE | ||||
The Constant directive allows you to declare your own constant values. While constants may appear to be the same as variables on the surface, there is one key difference. Unlike variables, who's value can't be changed after they are defined, so once a contant is declared it can not be changed. FACTS: * PlayBASIC will pre-evaluate constant expressions where possible (operations between constants), as well as some built in core functions. * Constants can be used with #IF/#ELSE/#ENDIF directives * Constants can only assign to expressions that resolve to be constant, since their are resolved at compile time, not run time. Mini Tutorial #1: This simple examples shows how to declare some Integer, Float# and String$ constants. You'll noticed that some those declarations are assigning expressions (formulas), this is only possible when the expressions are solely made up constants and or pre-solvable functions. Most of the core functions in PlayBASIC are solvable at compile time, providing they are given constant parameters, but not all.
This example would output.
Mini Tutorial #2: In this example we're using a constant to scale a series of values in some data statements by using pre-evaluation features of PlayBasic. What happens, is PB will resolve the expressions in the data statements during the compile. So it only stores the result of each calculation, not the code calculation code itself. Now it only do this with expressions that working upon constant / literal values.
|
Related Info: | #IF | AC | Dim | Explicit | Global | Literals | Local | Static | Variables : |
|
|||||||||||||||||||||||||||||||||||||||
(c) Copyright 2002 - 2024 - Kevin Picone - PlayBASIC.com |