Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Saving variables

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
0
0
How do I save variables so that when I exit out of qbasic and then reenter, and choose to load that the variables that were saved before I exited qbasic will be loaded?
 
Try looking in the help file at Open#, Close#, Write#, Read# for file saving/reading. [sig]<p>Karl<br><a href=mailto:kb244@kb244.com>kb244@kb244.com</a><br><a href= </a><br>Experienced in : C++(both VC++ and Borland),VB1(dos) thru VB6, Delphi 3 pro, HTML, Visual InterDev 6(ASP(WebProgramming/Vbscript)<br>
[/sig]
 
It's easiest to do by saving them into a simple ascii file.

If you know the maximum length of your variables, use a binary file. (I like to try and keep my numeric variables below 255, and use numeric variables whenever possible. This way you can use a single ASCII code as the value of the variable, and keep your variable files TINY, but I'm getting off subject.)

However, for variable length variables, the standard input-output file is simple enough.

Pretend that you have two variables, txtFirstName$ and txtLastName$ that you want to recover next time. All you have to do is the following:

'Open a file to store your variables in.
OPEN &quot;TempVars.TXT&quot; FOR OUTPUT AS #1

'Write the variables (in proper order) to the newly opened file.
PRINT #1, txtFirstName$
PRINT #1, txtLastName$

'Close and save the file.
CLOSE #1

'Now to recover them, just open the file for input:
OPEN &quot;TempVars.TXT&quot; FOR INPUT AS #1

'Now bring the information back into your variables. (The variable names can even be different.) The variables will be recovered in the same order that you wrote them into the file.
LINE INPUT #1, txtFirstName$
LINE INPUT #1, txtLastName$

'Close the file.
CLOSE #1

It's just that easy.

-Javin [sig]<p>Javin<br><a href=mailto:Javin@Javin-Inc.com>Javin@Javin-Inc.com</a><br><a href= Inc.</a><br><br>
Why don't sheep shrink when it rains?[/sig]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top