Reads values stored with the
Data statement.
Syntax
Read variable_list
Description
Reads data stored in the application with the
Data command.
The elements of the
variable_list must be of basic types, numeric, strings or elements of arrays and user defined types.
All the
Data statements in the program behave as a single list, after the last element of a
Data statement is read, the first element of the following
Data statement will be read. If a
Read is attempted after the last element of the last data element, an error will occur.
Data constants can only be of simple types (numeric or string). Alphanumeric string constants must be enclosed in quotes.
A numeric value can be read as a numeric literal into a string. A string read into a numeric variable will be evaluated by the
Val function.
The
Restore statement resets the next-element pointer to the start of the
Data following the label. This allows to alter the order in which the data is read.
Example
' Create an array of 5 integers and a string to hold the data.
Dim h(4) As Integer
Dim hs As String
Dim read_data As Integer
' Set up to loop 5 times (for 5 numbers... check the data)
For read_data = 0 To 4
' Read in an integer.
Read h(read_data)
' Display it.
Print "Number"; read_data;" = "; h(read_data)
Next
' Spacer.
Print
' Read in a string.
Read hs
' Print it.
Print "String = " + hs
' Await a keypress.
Sleep
' Exit program.
End
' Block of data.
Data 3, 234, 4354, 23433, 87643, "Bye!"
Dialect Differences
- The -lang fb and -lang fblite dialects consider data items as constant expressions that are evaluated during compilation and its result stored in the program.
- The -lang qb dialect considers data items as literals and stores then without change, as in QB.
Differences from QB
- In FreeBASIC, alphabetic string literals now must be enclosed within quotation marks, in QB this was optional.
- In QB, empty constant expressions evaluated to number 0 or to empty strings, in FreeBASIC they give a compile error.
See also