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 RESTORE statement is used to reset the DATA pointer to the beginning of the data.


RESTORE [lineNumber lineLabel]



Restoring a labeled DATA field to avoid going past the end of DATA.

   INPUT "Enter a month number(1 to 12): ", monthnum%

   RESTORE Months
   FOR i = 1 TO monthnum%
      READ month$, days%   'variables must match data field types
   PRINT "The month "; month$; " has"; days%; "days."
LOOP UNTIL monthnum% < 1 OR monthnum% > 12

 DATA January, 31, February, 28, March, 31, April, 30, May, 31, June, 30
 DATA July, 31, August, 31, September, 30, October, 31, November, 30, December, 31

Enter a month number(1 to 12): 6
The month June has 30 days.

Note: String DATA values do not require quotes unless they have commas, end spaces or QBasic keywords in them.

Using RESTORE to know the number of elements in the DATA in order to dimension and store the items in a array.

READ dummy$ 'we won't actually use this string for anything else than to know when there is no more DATA.
count = count + 1
LOOP UNTIL dummy$ = "stop" 'when dummy$ = "stop" then we know that it is the last entry so it only does the above loop until then.

count = count - 1 'since the last string is "stop" and we don't want to store it in the array.

PRINT "The number of relevant entries are:"; count

DIM entry$(count) 'Now we know how many elements we need to make space for (DIM)

RESTORE 'We restore it so that it begins reading from the first DATA again.

FOR c = 1 TO count
READ entry$(c) 'read the DATA and store it into the array.

'we can now print the contents of the array:

FOR c = 1 TO count 
PRINT entry$(c)


DATA "entry1", "entry2", "entry3", "stop"

The number of relevant entries are: 3

Note: Now we can add any number of entries without further compensation to the code.

See Also