Saving+variables+as+Text+Files

You can save data values in a text file for later retrieval.

You need to first, create the text file:

code format="lb" open "savegame.txt" for output as #savegame code

This line opens a file to write data into it. You then 'print' data into the file:

code format="lb" print #savegame, firstValue code

You should then use commas to separate the data values.

code format="lb" print #savegame, firstValue + "," + secondValue code

Once you are done writing into the file, you need to close the file:

code format="lb" close #savegame code

Now, to load data from the file, you need to reopen the file later on:

code format="lb" open "savegame.txt" for input as #savegame code

We can then 'input' the data into an array (or variables):

code format="lb" while eof(#savegame) = 0 for n = 1 to 2 input #savegame, loadedVars(n,1) next n wend code

This now will have loadedVars array with the firstValue (1,1) and then the secondValue (2,1) etc.

N.B. //while eof(#savegame) = 0// means that the while/wend loop will run until the end of the file is reached, and then the code will continue.