Liberty BASIC Help Online |
READ
Description:
This fetches the next strings and/or numeric values from DATA statements in a program. The READ statement will fetch enough items to fill the variable names the programmer specifies. The values fetched will be converted to fit the variables listed (string or numeric).
Example:
'read the numbers and their descriptions
while desc$ <> "end"
read desc$, value
print desc$; " is the name for "; value
wend
'here is our data
data "one hundred", 100, "two", 2, "three", 3, "end", 0
end
You can also read numeric items:
'read the numbers and their descriptions
while desc$ <> "end"
read desc$, value$
print desc$; " is the name for "; value$; ", length="; len(value$)
wend
'here is our data
data "one hundred", 100, "two", 2, "three", 3, "end", 0
end
Error Handling
If you try to read more DATA items than are contained in the DATA lists, the program will halt with an error. Notice that in the examples above, an "end" tag is placed in the DATA and when it is reached, the program stops READing DATA. This is an excellent way to prevent errors from occurring. If an end tag or flag of some sort is not used, be sure that other checks are in place to prevent the READ statement from trying to access more DATA items than are contained in the DATA statements.
Copyright (C) 2003 Shoptalk Systems
Liberty BASIC - http://www.libertybasic.com/