173 lines
4.1 KiB
QBasic
173 lines
4.1 KiB
QBasic
' ============================================================
|
|
' Test program for DATA/READ/RESTORE statements
|
|
' All DATA items form a single global pool, read sequentially.
|
|
' ============================================================
|
|
|
|
' All DATA statements (pool order matters)
|
|
DATA 10, 20, 30
|
|
DATA "Hello", "World", "BASIC"
|
|
DATA 42, "Alice", 3.14, "Bob", 100
|
|
DATA -5, -10, -3.14
|
|
DATA 1.5, 2.7, 3.9, 4.1
|
|
|
|
PRINT "==== DATA/READ/RESTORE Tests ===="
|
|
|
|
' ---- Test 1: Simple integer DATA/READ ----
|
|
PRINT ""
|
|
PRINT "---- Test 1: Integer DATA/READ ----"
|
|
DIM a AS INTEGER
|
|
DIM b AS INTEGER
|
|
DIM c AS INTEGER
|
|
READ a, b, c
|
|
PRINT "Read: "; a; " "; b; " "; c
|
|
|
|
' ---- Test 2: String DATA/READ ----
|
|
PRINT ""
|
|
PRINT "---- Test 2: String DATA/READ ----"
|
|
DIM s1$ AS STRING
|
|
DIM s2$ AS STRING
|
|
DIM s3$ AS STRING
|
|
READ s1$, s2$, s3$
|
|
PRINT "Read: "; s1$; " "; s2$; " "; s3$
|
|
|
|
' ---- Test 3: Mixed types ----
|
|
PRINT ""
|
|
PRINT "---- Test 3: Mixed types ----"
|
|
DIM n AS INTEGER
|
|
DIM name$ AS STRING
|
|
DIM pi AS DOUBLE
|
|
DIM name2$ AS STRING
|
|
DIM m AS INTEGER
|
|
READ n, name$, pi, name2$, m
|
|
PRINT "Int: "; n
|
|
PRINT "Str: "; name$
|
|
PRINT "Dbl: "; pi
|
|
PRINT "Str: "; name2$
|
|
PRINT "Int: "; m
|
|
|
|
' ---- Test 4: Negative numbers ----
|
|
PRINT ""
|
|
PRINT "---- Test 4: Negative numbers ----"
|
|
DIM neg1 AS INTEGER
|
|
DIM neg2 AS INTEGER
|
|
DIM neg3 AS DOUBLE
|
|
READ neg1, neg2, neg3
|
|
PRINT "Negatives: "; neg1; " "; neg2; " "; neg3
|
|
|
|
' ---- Test 5: Double values ----
|
|
PRINT ""
|
|
PRINT "---- Test 5: Double values ----"
|
|
DIM f1 AS DOUBLE
|
|
DIM f2 AS DOUBLE
|
|
DIM f3 AS DOUBLE
|
|
DIM f4 AS DOUBLE
|
|
READ f1, f2, f3, f4
|
|
PRINT "Doubles: "; f1; " "; f2; " "; f3; " "; f4
|
|
|
|
' ---- Test 6: RESTORE (reset to beginning) ----
|
|
PRINT ""
|
|
PRINT "---- Test 6: RESTORE ----"
|
|
RESTORE
|
|
DIM ra AS INTEGER
|
|
DIM rb AS INTEGER
|
|
DIM rc AS INTEGER
|
|
READ ra, rb, rc
|
|
PRINT "After RESTORE: "; ra; " "; rb; " "; rc
|
|
|
|
' ---- Test 7: READ in a loop ----
|
|
PRINT ""
|
|
PRINT "---- Test 7: READ in loop ----"
|
|
RESTORE
|
|
DIM val AS INTEGER
|
|
DIM i AS INTEGER
|
|
PRINT "First 3 via loop: ";
|
|
FOR i = 1 TO 3
|
|
READ val
|
|
PRINT val; " ";
|
|
NEXT i
|
|
PRINT ""
|
|
|
|
' ---- Test 8: RESTORE then skip with multiple READs ----
|
|
PRINT ""
|
|
PRINT "---- Test 8: Skip and read ----"
|
|
RESTORE
|
|
' Skip first 3 integers
|
|
DIM skip AS INTEGER
|
|
READ skip, skip, skip
|
|
' Now read the 3 strings
|
|
DIM rs1$ AS STRING
|
|
DIM rs2$ AS STRING
|
|
DIM rs3$ AS STRING
|
|
READ rs1$, rs2$, rs3$
|
|
PRINT "Skipped to strings: "; rs1$; " "; rs2$; " "; rs3$
|
|
|
|
' ---- Test 9: RESTORE with line number ----
|
|
PRINT ""
|
|
PRINT "---- Test 9: RESTORE with line number ----"
|
|
9000 DATA 111, 222, 333
|
|
9010 DATA 444, 555, 666
|
|
RESTORE 9010
|
|
DIM r1 AS INTEGER
|
|
DIM r2 AS INTEGER
|
|
DIM r3 AS INTEGER
|
|
READ r1, r2, r3
|
|
PRINT "RESTORE 9010: "; r1; " "; r2; " "; r3
|
|
|
|
RESTORE 9000
|
|
READ r1, r2, r3
|
|
PRINT "RESTORE 9000: "; r1; " "; r2; " "; r3
|
|
|
|
' ---- Test 10: Typed variables ----
|
|
PRINT ""
|
|
PRINT "---- Test 10: Typed variables ----"
|
|
DATA 200, 1000, 100000, 1.5
|
|
RESTORE
|
|
' Skip to the typed-variable DATA at the end.
|
|
' The pool has: 10,20,30, Hello,World,BASIC, 42,Alice,3.14,Bob,100,
|
|
' -5,-10,-3.14, 1.5,2.7,3.9,4.1, 111,222,333, 444,555,666, 200,1000,100000,1.5
|
|
' Items 23-26 are 200,1000,100000,1.5
|
|
' Use a known restore point instead: just re-read after RESTORE
|
|
' Actually, let's just read in order after a targeted DATA
|
|
9020 DATA 255, 32000, 100000, 2.5
|
|
RESTORE 9020
|
|
DIM bval AS BYTE
|
|
DIM ival AS INTEGER
|
|
DIM lval AS LONG
|
|
DIM fval AS FLOAT
|
|
READ bval, ival, lval, fval
|
|
PRINT "BYTE: "; bval
|
|
PRINT "INTEGER: "; ival
|
|
PRINT "LONG: "; lval
|
|
PRINT "FLOAT: "; fval
|
|
|
|
' ---- Test 11: Re-read same data ----
|
|
PRINT ""
|
|
PRINT "---- Test 11: Re-read same data ----"
|
|
RESTORE 9020
|
|
READ bval, ival, lval, fval
|
|
PRINT "Re-read BYTE: "; bval
|
|
PRINT "Re-read INTEGER: "; ival
|
|
|
|
' ---- Test 12: RESTORE with named label ----
|
|
PRINT ""
|
|
PRINT "---- Test 12: RESTORE with named label ----"
|
|
myData: DATA 777, 888, 999
|
|
moreData: DATA 50, 60, 70
|
|
RESTORE myData
|
|
DIM nd1 AS INTEGER
|
|
DIM nd2 AS INTEGER
|
|
DIM nd3 AS INTEGER
|
|
READ nd1, nd2, nd3
|
|
PRINT "RESTORE myData: "; nd1; " "; nd2; " "; nd3
|
|
|
|
RESTORE moreData
|
|
READ nd1, nd2, nd3
|
|
PRINT "RESTORE moreData: "; nd1; " "; nd2; " "; nd3
|
|
|
|
' Re-read from named label again
|
|
RESTORE myData
|
|
READ nd1
|
|
PRINT "Re-read first from myData: "; nd1
|
|
|
|
PRINT ""
|
|
PRINT "==== ALL DATA/READ/RESTORE TESTS COMPLETE ===="
|