QB64.com

QB64 is a modern extended BASIC programming language that retains QBasic/QuickBASIC 4.5 compatibility and compiles native binaries for Windows, Linux, and macOS.

The DATA statement creates a line of fixed program information separated by commas. The DATA can be later READ by the program at runtime.

Syntax

DATA [value1, value2, …]

Description

Example(s)

Creating two DATA fields that can be READ repeatedly using RESTORE with the appropriate line label.


RESTORE Database2
READ A$, B$, C$, D$         'read 4 string values from second DATA field
PRINT A$ + B$ + C$ + D$     'note that quoted strings values are spaced

RESTORE Database1
FOR i = 1 TO 18
  READ number%                     'read first DATA field 18 times only
  PRINT number%;                   
NEXT

END

Database1:
DATA 1, 0, 0, 1, 1, 0, 1, 1, 1
DATA 2, 0, 0, 2, 2, 0, 2, 2, 2 :       ' DATA line comments require a colon

Database2:
DATA "Hello, ", "world! ", Goodbye, work! 


Hello world! Goodbyework!
1  0  0  1  1  0  1  1  1  2  0  0  2  2  0  2  2  2

How to RESTORE and READ DATA in a SUB procedure in QB64. Line labels can be used for multiple DATA fields.


DIM SHARED num(10) 'shared array or must be passed as a parameter
ReadData 2 '<<<<<<< change value to 1 to read other data
FOR i = 1 TO 10
  PRINT num(i);
NEXT
END

SUB ReadData (mode)
IF mode = 1 THEN RESTORE mydata1 ELSE RESTORE mydata2
FOR i = 1 TO 10
  READ num(i)
NEXT

mydata1:
DATA 1,2,3,4,5,6,7,8,9,10
mydata2:
DATA 10,9,8,7,6,5,4,3,2,1
END SUB 


 10  9  8  7  6  5  4  3  2  1 

See Also