| variable - where to put the next value; a variable, an array slot or a type field, of integer, float or string type |
|
Reads the next value from the program's Data statements. Each Read takes one item from the Data list and moves the position on, so a loop empties a block a value at a time: Restore level1 For i = 0 To 63 Read tile(i) Next List several targets on one line to read a record at a time: Read name$, hp, speed#. They are filled left to right from consecutive Data values. The conversion is automatic. Read into an integer and a float value is truncated and a string of digits is parsed; read into a string and a number arrives as text. That is what lets one Data line hold a name, a hit-point total and a speed together. Read only fills plain values - a variable, an array element, a field of a type object. It cannot read into an object variable itself ("Data can not be read into an object"), nor into a Const. Build the object with New first, then Read into its fields. When the list runs out the program stops with "Out of data". A block whose length you are not sure of is best terminated with a marker value - read into a temporary, check for the marker, and stop the loop when it turns up. See also: Data, Restore, Dim, For. |
; Read Example
; ------------
; Point the Data pointer at the high score table
Restore high_scores
; Read fetches the next Data value each time it is called
Read entries
Print "High score table:"
For i=1 To entries
; Each entry mixes types - Read them in the order they were written
Read name$
Read score
Read accuracy#
Print " "+name$+" - "+score+" points ("+accuracy#+"% accuracy)"
Next
Print ""
Print "Press any key to close the example"
WaitKey
End
; First the number of entries, then name, score and accuracy for each
.high_scores
Data 3
Data "Ace",12500,91.5
Data "Bax",9800,77.25
Data "Cid",7350,64.0