View Full Version : Put problems with Qbasic


Spectrum
08-16-07, 09:22 AM
I'm having problems with the put command in Qbasic. Whenever I open a file to put data into it, the target file line or letter(s) appear blank. Anyone know what the problem is and/or how to fix it?

Cyperium
08-16-07, 12:11 PM
I'm having problems with the put command in Qbasic. Whenever I open a file to put data into it, the target file line or letter(s) appear blank. Anyone know what the problem is and/or how to fix it?First of all, you put bytes into the file, not letters, so that might be the problem...If you PUT something in the file at a certain position in it, then you can use GET the same way to retrieve the byte at that position, it should be there.

It was long ago since I used GET and PUT to insert things in files, I usually use INPUT and PRINT, but I think that was how it worked.

leopold99
08-16-07, 02:37 PM
It was long ago since I used GET and PUT to insert things in files,
me too, it's the major reason i haven't responded until now.
here's what i know.
first of all it all depends on how you OPEN the file. you can OPEN it for random access or to APPEND bytes to the end. random access means exactly that, you can access any byte anywhere in the file but you must access the entire record the byte resides in. when you OPEN for APPEND then you cannot retrieve any bytes, you can only add bytes to the end of the file and that must be one entire record.
each record in both cases comprise of a number of fields.
okay, that's about all of the preliminaries. now, there are only three reasons you will get a null return.
1. you have OPENed the file for APPEND. you can only add to the file in this case.
2. you are tyring to GET an nonexisting record or field. in this case you should get a EOF error.
3. there is nothing in the file.
I usually use INPUT and PRINT, but I think that was how it worked.
the way it worked for IBM is feild 3 as a$, 5 as b$ . . . etc .
you had to get an entire record and assign each variable as a number of bytes. in the example above the GET command would retrieve one record, then starting with byte 1 assign 3 bytes to A$, the next 5 bytes to B$, etc.

clear as mud?

edit
one other thing, the CLOSE command.
when you OPEN a file you open it in a certain slot, say 1. when you are done working with that file you CLOSE 1.
CLOSE without a number closes all open files.
this leads to a fourth options to the 3 above.
4. the file isn't open. in other words it never was or it was inadvertently closed.

edit2
okay, for the syntax. bear with me and please don't nail me to the wall on this because it's been like 35 years.
OPEN 1,"filespec" random ' this opens the file "filespec" in slot 1 for random access.
' the next line fields the record, the numbers MUST equal the record length.
feild 5 as A$, 2 as Z$, 25 as N$ ' the record in this case is 32 bytes.
get 7 ' this gets record 7 and assigns the variables in the feild statement.
' do some stuff to the variables.
r$=a$+z$+n$ parse the record
put 1,7 r$ ' returns the record.

Zephyr
08-16-07, 04:03 PM
I think Python is more logical than BASIC.

leopold99
08-16-07, 04:22 PM
I think Python is more logical than BASIC.
you must remember that most of this is a carry over from the earliest years of programming and dealt mainly with mailing lists.
you had a name, address, city, state, zip, and phone.
this info usually constituted one record. you would allow a set number of bytes for each one.

or when dealing with part numbers. you had the number and description, maybe even the price. this also constituted one record.

edit
also these commands dealt directly with the disk.
in windows the entire file is loaded into memory to be worked on. when you saved the file the entire file is rewritten to the disk. this isn't the case with the OPEN, GET, PUT commands. one can see from the above one of the reasons DOS was faster than any shell such as windows.

Spectrum
08-17-07, 06:57 AM
I thought it was a problem with Qbasic but if you guys don't have any problems then perhaps it isn't. I would use write but it puts inverted commas around the data. Here's what I'm putting:

Open "file" for random as #1 len=1
field #1, 1 as a$
put #1, 1

If I type:

put #1, 1, a$

then I get an error.

leopold99
08-17-07, 09:09 AM
what is the error you get?

edit:
i have scrounged up my winME cd and lo it has quickbasic on it.
i've dragged the directory to my HDD and now have access to it and the help files.
the program will start but will not shut down properly. this shouldn't affect the help file though. i doubt if i will be able to run any programs with it though.

from what i gather from the help files the syntax you are using appears correct.
the only thing i can see is that you are not using the complete file name. try using the file name AND the extension.
i need to know what error you are getting.

edit2
there are 2 more commands that are associated with OPEN that you need to know about if you plan on doing anything serious with your programs.
they are LSET and RSET.