DATA/de
Contents |
= (**COPIED FROM ENGLISH PAGE**) === Action
Specifies constant values to be read by subsequent READ statements.
Syntax
DATA var [, varn]
Remarks
Var |
Numeric or string constant. |
The DATA related statements use the internal registers pair R8 and R9 to store the data pointer.
To store a " sign on the data line, you can use :
DATA $34
The $-sign tells the compiler that the ASCII value will follow.
You can use this also to store special characters that can't be written by the editor such as chr(7)
Another way to include special ASCII characters in your string constant is to use {XXX}. You need to include exactly 3 digits representing the ASCII character. For example 65 is the ASCII number for the character A.
DATA "TEST{065}"
Will be read as TESTA.
While :
DATA "TEST{65}" will be read as :
TEST{65}. This because only 2 digits were included instead of 3.
{xxx} works only for string constants. It will also work in a normal string assignment :
s = "{065}" . This will assign A to the string s.
Because the DATA statements allow you to generate an EEP file to store in EEPROM, the $DATA and $EEPROM directives have been added. Read the description of these directives to learn more about the DATA statement.
The DATA statements must not be accessed by the flow of your program because the DATA statements are converted to the byte representation of the DATA.
When your program flow enters the DATA lines, unpredictable results will occur.
So as in QB, the DATA statement is best be placed at the end of your program or in a place that program flow will no enter.
For example this is fine:
Print "Hello"
Goto jump
DATA "test"
Jump:
'because we jump over the data lines there is no problem.
The following example will case some problems:
Dim S As String * 10
Print "Hello"
Restore lbl
Read S
DATA "test"
Print S
When the END statement is used it must be placed BEFORE the DATA lines.
Difference with QB
Integer and Word constants must end with the %-sign.
Long constants must end with the &-sign.
Single constants must end with the !-sign.
Double constants must end with the #-sign.
Siehe auch
READ , RESTORE , $DATA , $EEPROM , LOOKUP, LOOKUPSTR , LOOKDOWN
Beispiel
'----------------------------------------------------------------------------------------- 'name : readdata.bas 'copyright : (c) 1995-2005, MCS Electronics 'purpose : demo : READ,RESTORE 'micro : Mega48 'suited for demo : yes 'commercial addon needed : no '----------------------------------------------------------------------------------------- $regfile = "m48def.dat" ' Mikrocontroller $crystal = 4000000 ' Taktfrequenz $baud = 19200 ' Baudrate $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 Dim A As Integer , B1 As Byte , Count As Byte Dim S As String * 15 Dim L As Long Restore Dta1 'Zeiger auf gespeicherte Daten setzen For Count = 1 To 3 'Für jedes Datenelement Read B1 : Print Count ; " " ; B1 Next Restore Dta2 'Zeiger aud Datentabelle setzen For Count = 1 To 2 'Für jedes Datenelement Read A : Print Count ; " " ; A Next Restore Dta3 Read S : Print S Read S : Print S Restore Dta4 Read L : Print L 'long type 'demonstration of readlabel Dim W As Iram Word At 8 Overlay ' location is used by restore pointer 'note that W does not use any RAM it is an overlayed pointer to the data pointer W = Loadlabel(dta1) ' loadlabel expects the labelname Read B1 Print B1 End Dta1: Data &B10 , &HFF , 10 Dta2: Data 1000% , -1% Dta3: Data "Hello" , "World" 'Zu beachten: Integer-Werte (>255 or <0) müssen mit einem %-Zeichen enden. 'Auch zu beachten: Der Datentyp muss dem Datentyp der Variablen im READ-Befehl entsprechen. Dta4: Data 123456789& 'Zu beachten: LONG-Werte müssen mit einem &-Zeichen enden. 'Auch zu beachten: Der Datentyp muss dem Datentyp der Variablen im READ-Befehl entsprechen.
Languages | English • Deutsch |
---|