CONST/de
(→(**COPIED FROM ENGLISH PAGE**) =) |
(→Remarks) |
||
Line 19: | Line 19: | ||
<span style="font-family: Arial;"> </span> | <span style="font-family: Arial;"> </span> | ||
− | = <span class="f_Header"> | + | = <span class="f_Header">Anmerkungen</span> = |
<div style="padding: 0px; margin: 0px 0px 0px 4px;"> | <div style="padding: 0px; margin: 0px 0px 0px 4px;"> | ||
{| width="567" cellspacing="0" cellpadding="1" border="1" style="border: 2px solid rgb(0, 0, 0); border-spacing: 0px; border-collapse: collapse;" | {| width="567" cellspacing="0" cellpadding="1" border="1" style="border: 2px solid rgb(0, 0, 0); border-spacing: 0px; border-collapse: collapse;" | ||
Line 27: | Line 27: | ||
| valign="top" width="100%" style="width: 426px; border: 1px solid rgb(0, 0, 0);" | | | valign="top" width="100%" style="width: 426px; border: 1px solid rgb(0, 0, 0);" | | ||
− | + | Der Name der Konstanten. | |
|- style="vertical-align: top;" | |- style="vertical-align: top;" | ||
Line 34: | Line 34: | ||
| valign="top" width="100%" style="width: 426px; border: 1px solid rgb(0, 0, 0);" | | | valign="top" width="100%" style="width: 426px; border: 1px solid rgb(0, 0, 0);" | | ||
− | + | Numerischer Wert für die Konstante. | |
|- style="vertical-align: top;" | |- style="vertical-align: top;" | ||
Line 41: | Line 41: | ||
| valign="top" width="100%" style="width: 426px; border: 1px solid rgb(0, 0, 0);" | | | valign="top" width="100%" style="width: 426px; border: 1px solid rgb(0, 0, 0);" | | ||
− | + | Zeichenketten-Wert für die Konstante. | |
|- style="vertical-align: top;" | |- style="vertical-align: top;" | ||
Line 48: | Line 48: | ||
| valign="top" width="100%" style="width: 426px; border: 1px solid rgb(0, 0, 0);" | | | valign="top" width="100%" style="width: 426px; border: 1px solid rgb(0, 0, 0);" | | ||
− | + | Ein Ausdruck (expression) der einen Wert für die Konstante ergibt. | |
|} | |} | ||
Line 54: | Line 54: | ||
<span style="font-family: Arial;"> </span> | <span style="font-family: Arial;"> </span> | ||
− | + | Konstanten benötigen keinen Programmspeicher weil sie nur als Referenz beim Kompilieren dienen. | |
− | + | Der Compiler ersetzt jedes Auftreten der Konstanten durch den entsprechenden Wert. | |
<span style="font-family: Arial;"> </span> | <span style="font-family: Arial;"> </span> | ||
− | + | Man kann eine Konstante verwenden um einem Wert einen sinnvollen Namen zu geben. | |
For example : variable = 1 | For example : variable = 1 | ||
Line 72: | Line 72: | ||
<span style="font-family: Arial;"> </span> | <span style="font-family: Arial;"> </span> | ||
− | + | Der Programmcode ist besser zu lesen wenn Konstanten verwendet werden. Darüberhinaus muss nur eine Zeile Programmcode geändert werden wenn später zum Beispiel HeaterOn 2 sein soll. | |
<span style="font-family: Arial;"> </span> | <span style="font-family: Arial;"> </span> |
Revision as of 01:42, 27 February 2013
Contents |
Funktion
Definiert eine symbolische Konstante.
Syntax
CONST symbol = numconst
CONST symbol = stringconst
CONST symbol = expression
Anmerkungen
Symbol |
Der Name der Konstanten. |
Numconst |
Numerischer Wert für die Konstante. |
Stringconst |
Zeichenketten-Wert für die Konstante. |
Expression |
Ein Ausdruck (expression) der einen Wert für die Konstante ergibt. |
Konstanten benötigen keinen Programmspeicher weil sie nur als Referenz beim Kompilieren dienen.
Der Compiler ersetzt jedes Auftreten der Konstanten durch den entsprechenden Wert.
Man kann eine Konstante verwenden um einem Wert einen sinnvollen Namen zu geben.
For example : variable = 1
const optHeaterOn = 1
variable = optHeaterOn
Der Programmcode ist besser zu lesen wenn Konstanten verwendet werden. Darüberhinaus muss nur eine Zeile Programmcode geändert werden wenn später zum Beispiel HeaterOn 2 sein soll.
See also
Example
'----------------------------------------------------------------------------------------- 'name : const.bas 'copyright : (c) 1995-2005, MCS Electronics 'purpose : demo for constants 'micro : Mega48 'suited for demo : yes 'commercial addon needed : no '----------------------------------------------------------------------------------------- $regfile = "m48def.dat" ' specify the used micro $crystal = 4000000 ' used crystal frequency $baud = 19200 ' use baud rate $hwstack = 32 ' default use 32 for the hardware stack $swstack = 10 ' default use 10 for the SW stack $framesize = 40 ' default use 40 for the frame space 'dimension some variables Dim Z As String * 10 Dim B As Byte 'assign some constants 'constants dont use program memory Const S = "test" Const A = 5 'declare a as a constant Const B1 = &B1001 'or use an expression to assign a constant Const X =(b1 * 3) + 2 Const Ssingle = Sin(1) Print X Print Ssingle B = A 'the same as b = 5 Z = S 'the same as Z = "test" Print A Print B1 Print S 'you can use constants with conditional compilation #if A = 5 ' note there is no then Print "constant a is 5" #if S = "test" Print "nested example" #else ' else is optional #endif #else #endif End
Languages | English • Deutsch |
---|