Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Saving information in Qbasic  (Read 7854 times)

0 Members and 1 Guest are viewing this topic.

Zylstra

    Topic Starter
  • Moderator


  • Hacker

  • The Techinator!
  • Thanked: 45
    • Yes
    • Technology News and Information
  • Certifications: List
  • Computer: Specs
  • Experience: Guru
  • OS: Windows 7
Saving information in Qbasic
« on: June 28, 2007, 12:11:33 AM »
Hello

I am looking for a more convenient way to save information in Qbasic.

Right now, I am using the following method:

Code: [Select]
open "pdata.dat" for random as #1
print "Type the data you would like to save"
input data$
put #1, 1, data$
cls
print "Type the next data you would like to save"
input data2$
put #1, 2, data2$
close #1
end
(thats only an example)

My problem is this:
The library system (put #1, 22, value$ ) is terrible inconvenient, and very hard to keep track of.

How can I make it so that its all saved without having to keep track of the numbers?


(I know, its Qbasic, and its getting more and more uncommon, but hey, its still compatible with Vista!)
I am using the full Qbasic compiler program, not the limited version

contrex

  • Guest
Re: Saving information in Qbasic
« Reply #1 on: June 28, 2007, 02:36:33 AM »
Ah, good old QBasic!

You are saving a string, why are you using open file for random? Why don't you just do this? Why the CLS? (You can't see what you typed before) Why don't you use LINE INPUT for the strings? (INPUT won't let you include a comma in the string)

Code: [Select]
open "pdata.dat" for output as #1
print "Type the data you would like to save"
input data$
print #1, data$
cls
print "Type the next data you would like to save"
input data2$
print #1, data2$
close #1
end

Why not do it in a loop? (Then you can type more than 2 strings)

Code: [Select]
open "pdata.dat" for output as #1
do
     print "Type data to save (ENTER to quit) ";
     line input data$
     if data$="" then exit do     
     print #1, data$
loop
close #1
end
« Last Edit: June 28, 2007, 05:11:37 AM by contrex »

Zylstra

    Topic Starter
  • Moderator


  • Hacker

  • The Techinator!
  • Thanked: 45
    • Yes
    • Technology News and Information
  • Certifications: List
  • Computer: Specs
  • Experience: Guru
  • OS: Windows 7
Re: Saving information in Qbasic
« Reply #2 on: June 28, 2007, 03:24:31 PM »
Ah, good old QBasic!

You are saving a string, why are you using open file for random? Why don't you just do this? Why the CLS? (You can't see what you typed before) Why don't you use LINE INPUT for the strings? (INPUT won't let you include a comma in the string)
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>

Why not do it in a loop? (Then you can type more than 2 strings)

Code: [Select]
open "pdata.dat" for output as #1
do
     print "Type data to save (ENTER to quit) ";
     line input data$
     if data$="" then exit do     
     print #1, data$
loop
close #1
end

I don't understand how loops work, to tell you the truth, I messed around with them once, but really didn't get it at all.

So I will need to be able to PUT the information, and GET it as well.

contrex

  • Guest
Re: Saving information in Qbasic
« Reply #3 on: June 28, 2007, 03:46:45 PM »
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.

Zylstra

    Topic Starter
  • Moderator


  • Hacker

  • The Techinator!
  • Thanked: 45
    • Yes
    • Technology News and Information
  • Certifications: List
  • Computer: Specs
  • Experience: Guru
  • OS: Windows 7
Re: Saving information in Qbasic
« Reply #4 on: June 28, 2007, 03:53:29 PM »
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


contrex

  • Guest
Re: Saving information in Qbasic
« Reply #5 on: June 29, 2007, 12:54:33 AM »
And would this be correct to retrieve the data again:

Quote
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

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?



Zylstra

    Topic Starter
  • Moderator


  • Hacker

  • The Techinator!
  • Thanked: 45
    • Yes
    • Technology News and Information
  • Certifications: List
  • Computer: Specs
  • Experience: Guru
  • OS: Windows 7
Re: Saving information in Qbasic
« Reply #6 on: June 29, 2007, 01:40:09 AM »
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)