Posts: 7
Threads: 3
Joined: Sep 2004
I have some questions...but answers seem too complicated for me
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:
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
Posts: 1,272
Threads: 36
Joined: Feb 2003
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.
Posts: 7
Threads: 3
Joined: Sep 2004
thank you for your answers ...they helped me a lot
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
Posts: 383
Threads: 14
Joined: Mar 2004
[syntax="qbasic"]
input"What means HTML : ",answer$
input "Choose filename: ", filename$
open filename$ + ".txt" for output as #1
print #1, answer$
close #1
[/syntax]
Posts: 7
Threads: 3
Joined: Sep 2004
Posts: 12
Threads: 2
Joined: Aug 2004
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.
hey say that if you play a Windows Install CD backwards, you can hear Satanic messages. That's nothing, play it forwards and it installs Windows.
Posts: 2,765
Threads: 138
Joined: Nov 2002
the extention does matter.
it could be .dat or .txt or .aaa
read it anyways though =P
Back by popular demand!
I will byte and nibble you bit by bit until nothing remains but crumbs.
Posts: 3,343
Threads: 83
Joined: Mar 2003
Files don't even need extensions (though this is normally good practice)
Posts: 538
Threads: 62
Joined: Apr 2003
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)
url=http://www.spreadfirefox.com/?q=affiliates&id=0&t=79]
[/url]
Posts: 3,279
Threads: 170
Joined: Nov 2003
You might want to reconsider your extension
.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.
I'd knock on wood, but my desk is particle board.