Const: Difference between revisions

From NSB App Studio
Jump to navigation Jump to search
Brendon (talk | contribs)
Created page with "CONST ''name''=''expression'' '''Description''' CONST declares constants, which can be used in expressions, in place of literal values. The required component, ''name'', mus..."
 
Brendon (talk | contribs)
No edit summary
Line 1: Line 1:
CONST ''name''=''expression''
Const ''name''=''expression''


'''Description'''
== Description ==


CONST declares constants, which can be used in expressions, in place of literal values. The required component, ''name'', must follow standard variable naming conventions. The required component, ''expression'', is any literal, constant, or combination that includes all arithmetic or logical operators (except IS).
Const declares constants, which can be used in expressions, in place of literal values. The required component, ''name'', must follow standard variable naming conventions. The required component, ''expression'', is any literal, constant, or combination that includes all arithmetic or logical operators (except IS).


All constants declared inside procedures are available only within the procedure. CONST works the same way as DIM, however it is used to identify variables whose value should not be changed.
All constants declared inside procedures are available only within the procedure. Const works the same way as DIM, however it is used to identify variables whose value should not be changed.


Multiple constants may be declared on a single line, by separating each constant assignment with a comma.
Multiple constants may be declared on a single line, by separating each constant assignment with a comma.


'''Example'''
== Example ==


<pre>
<pre>
REM CONST Example
REM Const Example
'CONST defines constants
'Const defines constants
CONST SHAPE = "Rectangle"
Const SHAPE = "Rectangle"
CONST AREA = 51
Const AREA = 51
CONST LENGTH = 7, WIDTH = 11
Const LENGTH = 7, WIDTH = 11
PrintArea LENGTH, WIDTH
PrintArea LENGTH, WIDTH
SUB PrintArea(l, w)
SUB PrintArea(l, w)
Line 25: Line 25:
</pre>
</pre>


'''Output'''
== Output ==


<pre>
<pre>
Line 31: Line 31:
</pre>
</pre>


'''Related Items'''
== Related Items ==


[[function|FUNCTION]], [[dim|DIM]], [[sub|SUB]]
[[function|FUNCTION]], [[dim|DIM]], [[sub|SUB]]
[[Category:Language Reference]]

Revision as of 20:25, 8 August 2012

Const name=expression

Description

Const declares constants, which can be used in expressions, in place of literal values. The required component, name, must follow standard variable naming conventions. The required component, expression, is any literal, constant, or combination that includes all arithmetic or logical operators (except IS).

All constants declared inside procedures are available only within the procedure. Const works the same way as DIM, however it is used to identify variables whose value should not be changed.

Multiple constants may be declared on a single line, by separating each constant assignment with a comma.

Example

REM Const Example
'Const defines constants
Const SHAPE = "Rectangle"
Const AREA = 51
Const LENGTH = 7, WIDTH = 11
PrintArea LENGTH, WIDTH
SUB PrintArea(l, w)
  DIM Area
  Area = l * w
  PRINT SHAPE & " area: " & l & " * " & w &" = " & Area
END SUB

Output

Rectangle area:7*11=77

Related Items

FUNCTION, DIM, SUB