Qbasicnews.com

Full Version: ! ! open"text.txt" for input & output ! ! ques
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
I have some questions...but answers seem too complicated for me Tongue

1)how do I save file with the name I want?
something like this

Code:
open "input"mychoosednamewhichIcantype" .txt" for output as #1
print #1
close

2)what does #1 mean? how does it help me anyway?
3)how can i read from the second line of file??

bla.txt:
Code:
Bond
Lights

qbasic program:
Code:
open"bla.txt" for input as #1
input #1.s$
print s$
close

but it will only print me the first line word, Bond...

so thank you if you wasted your time helping me Smile
1)
Code:
INPUT youCanUseAStringVariable$
OPEN youCanUseAStringVariable$ FOR OUTPUT AS #1

2)
You can open more than one file at a time. For example, to copy stuff from "source.dat" to "dest.dat", you could make "source.dat" #1, and "dest.dat" #2.

You can pick any number you want, even #53 should work.

3)
The first time, INPUT gives you the first line. But if you do it again, it'll give you the second, etc... example:
Code:
OPEN "blah.txt" FOR INPUT AS #1
LINE INPUT #1, firstLine$
PRINT firstLine$
LINE INPUT #1, secondLine$
PRINT secondLine$
CLOSE
...and you could put LINE INPUT in a loop if you want to get a lot of lines.
thank you for your answers ...they helped me a lot Smile
still...when I looked at these questions, one thing came to mind...how do I save some certain text?

let's say i have an input form,
Code:
input"What means HTML : ";answer$
where i have typed: Hyper Text Markup Language...how can i save my answer??

well...and let's say I want to choose a name for this file? how would the code then look like?


started learning qbasic by myself last night and already I have so many ideas...and questions Tongue
[syntax="qbasic"]
input"What means HTML : ",answer$
input "Choose filename: ", filename$
open filename$ + ".txt" for output as #1
print #1, answer$
close #1
[/syntax]
thanks :wink:
In response to #3... although you could, as Sterling suggested, loop LINE INPUT, I would suggest switching over to .dat files if you're going to want to write multiple lines at a time in a file... MUUUUCH easier. For information on .dat files... read the "Random Access Files" section of http://www.qbasic.com/chapter5.txt.
the extention does matter.
it could be .dat or .txt or .aaa


read it anyways though =P
Files don't even need extensions (though this is normally good practice) Wink
like with my programs, my word procesor used .gdm files, and my ftp program used .gf extension to save logs, (not to self:i shud finish that, now if only i cud find the disk)
You might want to reconsider your extension Wink .gdm is used for General Digital Music, and is the native format (and extension) for the BWSB sound library. If I were you, I'd try to find an extension that's not already being used...you can get a good list of used extensions at wotsit.org.
Pages: 1 2