InterviewSolution
| 1. |
Solve : Saving information in Qbasic? |
|
Answer» Hello Ah, good old QBasic!I am using the Random statement so that I can both save, and open the file. I understand that I can save information using the OUTPUT statement, but I cannot retrieve it. (Well, not without closing the file, opening it again) The code I posted was just an example, thus, the CLS and whatever else is pointless Quote <snip> So I will need to be able to PUT the information, and GET it as well. If you don't like having "magic numbers" in your code, and I don't blame you, (it is bad practice) you can use numeric variables and increment them each time. Code: [Select]open "pdata.dat" for random as #1 n=1 print "Type the data you would like to save" input data$ put #1, n, data$ : n=n+1 cls print "Type the next data you would like to save" input data2$ put #1, n, data2$ : n=n+1 close #1 end You should try with loops. they not complicated. Things just got round and round until it's time to stop. I will GIVE that a try The Qbasic library system is terrible, I just hope more than ever that this will work out How well will it function with Subs if they were to go out of order? And would this be correct to retrieve the data again: Code: [Select]open "pdata.dat" for random as #1 n=w print "Type your info" input data2$ put #1, n, data2$ : n=n+1 cls get #1, n, data2$ : n=n+1 close #1 Quote from: Zylstra on June 28, 2007, 03:53:29 PM And would this be correct to retrieve the data again: Quote open "pdata.dat" for random as #1 No, because what you are doing is 1. Ask the user to type a string 2. PUT that string to record number N 3. Increase the value of N by 1 4. GET record number N So you will GET the next record after the ONE that you wrote, which may not even exist YET, and is certainly not the one that you want. Hint: Run your code to see if it works! If you had put a "PRINT data2$" at the end of that code, you could have tested it. Why are you doing all this QBasic stuff? I'll try it out I like to program in Qbasic for no reason at all, but sometimes I make something for myself, I was trying to write a registry-type system that could be intergraded into my programs but I ran into a problem that can be fixed with your suggestion. Also, I use it for resuming sessions in my random programs (thus why I have to use GET and PUT at the same time) |
|