Const: Difference between revisions

From NSB App Studio
Jump to navigation Jump to search
(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...")
 
No edit summary
 
(10 intermediate revisions by 2 users not shown)
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>
<tabber>
REM CONST Example
JavaScript=
'CONST defines constants
<syntaxhighlight lang="JavaScript">
CONST SHAPE = "Rectangle"
//Const Example
CONST AREA = 51
//Const defines constants
CONST LENGTH = 7, WIDTH = 11
 
const SHAPE = "Rectangle";
const AREA = 51;
const LENGTH = 7, WIDTH = 11;
PrintArea(LENGTH, WIDTH);
function PrintArea(l, w) {
  var Area;
  Area = l * w;
  NSB.Print(SHAPE + " area: " + l  +  " * " + w  + " = " + Area);
}
</syntaxhighlight>
|-|
BASIC=
<syntaxhighlight lang="vb.net">
Rem Const Example
'Const defines constants
 
Const SHAPE = "Rectangle"
Const AREA = 51
Const LENGTH = 7, WIDTH = 11
PrintArea LENGTH, WIDTH
PrintArea LENGTH, WIDTH
SUB PrintArea(l, w)
Sub PrintArea(l, w)
   DIM Area
   Dim Area
   Area = l * w
   Area = l * w
   PRINT SHAPE & " area: " & l & " * " & w &" = " & Area
   Print SHAPE & " area: " & l & " * " & w &" = " & Area
END SUB
END Sub
</pre>
</syntaxhighlight>
</tabber>


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


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


'''Related Items'''
== Related Items ==
 
[[dim|Dim]], [[function|Function]], [[sub|Sub]]
 
[[Category:Language Reference]]


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

Latest revision as of 14:03, 24 July 2019

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

//Const Example
//Const defines constants

const SHAPE = "Rectangle";
const AREA = 51;
const LENGTH = 7, WIDTH = 11;
PrintArea(LENGTH, WIDTH);
function PrintArea(l, w) {
  var Area;
  Area = l * w;
  NSB.Print(SHAPE + " area: " + l  +  " * " + w  + " = " + Area);
}

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

Dim, Function, Sub