Qbasicnews.com

Full Version: very new...
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
update further down page :wink:

well the subject says it all and while i can say i am hapy to be tyeaching myself Qbasic i am said to say i am stuck :oops: i cannot seem to get my head around saving files in qbasic i have been messing around with the OPEN, GET, PUT and any number of other commands to do with saving but i can't seem to get them to function this isn't for anything i just wanted to see if i could do it Big Grin any input would be wonderful
Can show us some of the stuff that you've tried? If we could have a look at what you're doing it might help to solve your problem faster and more specifically.
i didn`t use tutorials to learn qb, but read alot of sourcecodes. anyways, i think mallard's tutorials are quite good:

http://www.qbasic.com/tutorial.shtml

cheers/mariuz
GET and PUT is a bit harder, atleast in my opinion, so start out with the OPEN statements.

For creating a new file use this

Code:
OPEN "test.dat" FOR OUTPUT AS #1
WRITE #1 "HI"
CLOSE #1

OPEN opens the file, but you must specify a file that is in quotes "". There is no location of the file, assuming that the file you want to create is in the same directory as QB. OUTPUT just creates a new file. Be careful not to overwrite files using that! WRITE command just simply writes to the file, so when you open it up it says "HI". If you don't want quotes, use PRINT # instead. Using the #1 just writes to the file that's OPENed as #1, so if you would want to be writing or whatever to another file you would have to use #2 or another number 1- 57 I think. And of course, you'll want to close the file before ending the prog, so you will have to use the CLOSE command.

Now if you want to add on to a file, without overwriting anything, use the APPEND keyword in place of OUTPUT.

Code:
OPEN "test.dat" FOR APPEND AS #1
WRITE #1 "HI"
CLOSE #1

That will add on to the end of test.dat

If you want to read from a file, for example, if you wanted to read the first line of a file and print it in qbasic, then use INPUT in place of APPEND

Code:
OPEN "test.dat" for OUTPUT as #1
PRINT #1, "pie"
CLOSE #1

OPEN "test.dat" for INPUT as #1
LINE INPUT #1, a$
PRINT a$
CLOSE #1

The code should print 'pie'

LINE INPUT reads the first line, then second time you use it reads the second line...etc

a$ is the string variable used to store what is on the first line. Then PRINT prints it, obviously.

Well, hope this helps, and if you need me to explain more just ask.
hey guys thanks for the input i have ever come my first saving issue thanks to the coding from offensive screenname and have had a fiddle with that Big Grin ...
and now i have another coding problem but i have more info this time around :roll: i have some coding from this list program and the bit i am intrested in goes like this

Code:
common shared nombrelista$
input nombrelista$
if len(nombrelista$) = 0 then

config$ = "makeconf.cfg"
open config$ for input access read as #2
input #2, nombrelista$
close #2
end if

now that works fine it makes a new file and everything but when i yped mine up it did nothing

Code:
common shared name56$
input name 56$
if len(name56$) = 0 then
name2$ = "makeconf.cfg."
open name2$ for input access read as #2
input #2, name 56$
close #2

end if

as you can see the look the same i fiddled with all the coding on mine and couldn't get it to work :oops: , also there is heaps more of the other guys coding i just took what i thought should run it :lol:

thanks for any advice
snorkel
A tip, use english variable names, it makes it a lot easier for others to read your code.

[syntax="QBASIC"]COMMON SHARED name56$
INPUT name56$
IF LEN(name56$) = 0 THEN
name2$ = "makeconf.cfg"
OPEN name2$ FOR INPUT ACCESS READ AS #2
INPUT #2, name56$
CLOSE #2
END IF [/syntax]

You can't have spaces in varnames either.

Filenames can only be 8.3 chars in DOS, that is, max 9 chars, followed by a dot, and then max 3 chars.