DATA c1[, c2[, c3[, ...]]] DATA AS type c1[, c2[, c3[, ...]]]
The DATA
command is used to store constant information in the program code,
and is used with the BASIC-command READ
. Each DATA
-line can contain one
or more constants separated by commas. Expressions containing variables
will not be evaluated here.
The instruction stores numeric data in an optimized way: so, if you enter a numeric
constant that can be represented by a single byte, it will be stored in the program
as a single byte. Floating point numbers are stored with default precision.
Finally, strings are stored “as is”. As a result, when you use the READ
command,
ugBASIC will implicitly perform the conversion if the same data type is not used,
and it is posssible. It is possible to avoid optimization by using the AS
keyword with the data type.
The DATA
values will be read from left to right, beginning with the first
line containing a DATA
statement. Each time a READ
instruction is
executed the saved DATA
position of the last READ
is advanced to the
next value. Strings must be written in quotes, so characters
like comma, space, colon, graphical ones or control characters has to be
written inside double quotes like string constants. The RESTORE
resets
the pointer of the current DATA
position the program start so that
next READ
will read from the first DATA
found from the beginning
of the program.
In case READ
uses the wrong variable type, variable will be untouched
and pointer will be left to the current position. There is no easy way
to get the position of the READ
statement which is the real origin of
the mismatch.
DATA
lines may scattered over the whole program code.
DATA 10, 20, "test" DATA AS INTEGER 10, 20, 30
See also the following example files:
Da
If you have encountered a problem using this command, if you think there is a bug or the explanation is unclear, please open an issue for this keyword on GitHub. Thank you!