Qbasicnews.com
October 19, 2021, 09:39:34 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Back to Qbasicnews.com | QB Online Help | FAQ | Chat | All Basic Code | QB Knowledge Base
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: ! ! open"text.txt" for input & output ! ! ques  (Read 6255 times)
-dezell-
New Member

Posts: 7



WWW
« on: September 01, 2004, 01:34:02 PM »

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 Smiley
Logged
Sterling Christensen
Na_th_an
*****
Posts: 1328


« Reply #1 on: September 01, 2004, 01:46:47 PM »

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.
Logged
-dezell-
New Member

Posts: 7



WWW
« Reply #2 on: September 01, 2004, 02:05:30 PM »

thank you for your answers ...they helped me a lot Smiley
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
Logged
HQSneaker
Wandering Guru
***
Posts: 394



WWW
« Reply #3 on: September 01, 2004, 02:29:49 PM »

[syntax="qbasic"]
input"What means HTML : ",answer$
input "Choose filename: ", filename$
open filename$ + ".txt" for output as #1
print #1, answer$
close #1
[/syntax]
Logged
-dezell-
New Member

Posts: 7



WWW
« Reply #4 on: September 01, 2004, 02:41:32 PM »

thanks  :wink:
Logged
frostyservant
New Member

Posts: 12


« Reply #5 on: September 02, 2004, 08:44:12 PM »

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.
Logged

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.
whitetiger0990
__/--\__
*****
Posts: 2964



WWW
« Reply #6 on: September 02, 2004, 08:46:23 PM »

the extention does matter.
it could be .dat or .txt or .aaa


read it anyways though =P
Logged


[size=10]Back by popular demand!
I will byte and nibble you bit by bit until nothing remains but crumbs.[/size]
oracle
*/-\*
*****
Posts: 3652



WWW
« Reply #7 on: September 02, 2004, 11:58:22 PM »

Files don't even need extensions (though this is normally good practice) Wink
Logged

Ruudboy
Ancient Guru
****
Posts: 544



« Reply #8 on: September 03, 2004, 01:40:37 PM »

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)
Logged

url=http://www.spreadfirefox.com/?q=affiliates&id=0&t=79][/url]
adosorken
*/-\*
*****
Posts: 3655



WWW
« Reply #9 on: September 03, 2004, 01:49:02 PM »

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.
Logged

I'd knock on wood, but my desk is particle board.
Ruudboy
Ancient Guru
****
Posts: 544



« Reply #10 on: September 03, 2004, 01:55:42 PM »

it's my extension so they can go 2 hell
Logged

url=http://www.spreadfirefox.com/?q=affiliates&id=0&t=79][/url]
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!