Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
! ! open"text.txt" for input & output ! ! ques
#1
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
Reply
#2
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.
Reply
#3
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
Reply
#4
[syntax="qbasic"]
input"What means HTML : ",answer$
input "Choose filename: ", filename$
open filename$ + ".txt" for output as #1
print #1, answer$
close #1
[/syntax]
Reply
#5
thanks :wink:
Reply
#6
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.
Reply
#7
the extention does matter.
it could be .dat or .txt or .aaa


read it anyways though =P
[Image: sig.php]
Back by popular demand!
I will byte and nibble you bit by bit until nothing remains but crumbs.
Reply
#8
Files don't even need extensions (though this is normally good practice) Wink
Reply
#9
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][Image: safer.gif][/url]
Reply
#10
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.
I'd knock on wood, but my desk is particle board.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)