READ

From QB64 Wiki
Revision as of 04:05, 3 September 2009 by imported>Clippy
Jump to navigation Jump to search

TheREAD: statement reads values from a DATA field and assigns them to variables.


Syntax: READ list$, of!, variables%


  • A READ statement must always be used with to READ a DATA statement.
  • READ statements assign variables to DATA statement values on a one-to-one basis.
  • READ statement variables may be numeric or string, and the values read must agree with the variable types specified. If they do not agree, a "Syntax error" results.
  • A single READ statement may access one or more DATA values. They are accessed in order.
  • Several READ statements may access the same DATA statement.
  • If the number of variables in list of variables exceeds the number of elements in the DATA statement(s), an "Out of data" message is printed.
  • If the number of variables specified is fewer than the number of elements in the DATA statement(s), subsequent READ statements begin reading data at the first unread element. If there are no subsequent READ statements, the extra data is ignored.
  • To reread DATA statements from the start, use the RESTORE statement.

Examples:

FOR I=1 TO 10
READ A(I)
NEXT I
DATA 3.08, 5.19, 3.12, 3.98, 4.24
DATA 5.08, 5.55, 4.00, 3.16, 3.37

This program segment reads the values from the DATA statements into array A. After execution, the value of A(1) is 3.08, and so on. The DATA statements may be placed anywhere in the program; they may even be placed ahead of the READ statement.

PRINT "CITY", "STATE", "ZIP"
READ C$, S$, Z
DATA "DENVER,", "COLORADO", 80211
PRINT C$, S$, Z

Screen Results:

CITY STATE ZIP
DENVER, COLORADO 80211


Navigation:

Go to Keyword Reference - Alphabetical

Go to Keyword Reference - By usage