Using DATA Statements |
Top Previous Next |
Emergence BASIC supports DATA statements through named data blocks. Any number of separate data blocks can be used in your program and there is no limit to the number of data items contained within a block. Defining a block of data The normal place to define a data block is at the end of your source file. Although they can appear anywhere. Begin the definition with the DATABEGIN statement and end with the DATAEND statement. Define the data items between the block using the DATA statement. DATABEGIN mydata The DATA statement accepts strings, Unicode strings, integers, floats and double precision literals. Variables are not allowed as the compiler has to resolve the data statement at compile time. DATA is limited to 100 items per line, separate your data for readability. The same basic math operations used for creating constants can be used when defining a data statement.
Reading data Data can be read by your program using the GETDATA function. GETDATA requires the name of the data block and a variable to store the read data into. The compiler will handle conversions between variable types so you can specify a float variable for double precision data if needed. DEF str as STRING Each use of GETDATA advances an internal pointer to the next data item in the list. There is no end of data marker so it is possible to read past the end of the data block. A common programming technique is to create your own marker using either a special number or an empty string for string data.. DEF sName as STRING Restoring the data pointer You can move the data pointer in the data block back to the beginning by using the RESTORE command RESTORE mydata After the restore GETDATA will read from the beginning of the data block. |