DATA, READ, RESTORE (V26)

DATA

Syntax: DATA value1, value2, ...

Stores literal values at compile time for use with READ. DATA statements typically appear at the end of the source file. Supports labelled DATA blocks.

FUNCTION PBMAIN() AS LONG
    LOCAL a AS LONG, b AS LONG, s AS STRING
    READ a, b, s
    PRINT a; b; s
    FUNCTION = 0
END FUNCTION

DATA 12, 34, "MASTER"

myData:
DATA 100, 200

READ

Syntax: READ var1 [, var2, ...]

Reads values sequentially from DATA statements into variables. Supports numeric and string variables. The DATA pointer advances after each READ.

LOCAL a AS LONG, s AS STRING
READ a, s
READ a

RESTORE

Syntax: RESTORE [label]

Resets the DATA pointer to the beginning of DATA statements. With a label, points to a specific labelled DATA block.

RESTORE          ' Reset to first DATA statement
RESTORE myData   ' Point to myData: block

Full Example

#COMPILE EXE "data_demo.exe"
#DIM ALL

FUNCTION PBMAIN() AS LONG
    LOCAL a AS LONG, b AS LONG, s AS STRING
    READ a, b, s
    PRINT a; b; " "; s
    RESTORE myData
    READ a, b
    PRINT a; b
    FUNCTION = 0
END FUNCTION

DATA 12, 34, "MASTER"

myData:
DATA 100, 200