Qbasicnews.com
Opening files - Printable Version

+- Qbasicnews.com (http://qbasicnews.com/newforum)
+-- Forum: QBasic (http://qbasicnews.com/newforum/forum-4.html)
+--- Forum: QB Discussion & Programming Help (http://qbasicnews.com/newforum/forum-11.html)
+--- Thread: Opening files (/thread-1457.html)



Opening files - Jsmith - 07-11-2003

This is a bit of a stupid problem, but I have a file with more than one line, and I can't work out how to print it. So far I've got:
OPEN "file.txt" FOR INPUT AS #1
INPUT #1, s$
CLOSE
PRINT s$

but that only prints the first line of the file.
How do I print the whole file?


You need a loop... - Glenn - 07-11-2003

OPEN "file.txt" FOR INPUT AS #1
WHILE NOT EOF(1)
LINE INPUT #1, s$
PRINT s$
WEND
CLOSE


Opening files - Moneo - 07-12-2003

JSmith,

I'f you're not comfortable with the WHILE/WEND, you can use a DO WHILE/LOOP as follows:
Code:
OPEN "file.txt" FOR INPUT AS #1
DO WHILE NOT EOF(1)
   LINE INPUT #1, s$
   PRINT s$
LOOP
SYSTEM



Opening files - whitetiger0990 - 07-12-2003

OPEN "file.txt" FOR INPUT AS #1
'Opens the file.

DO WHILE NOT EOF(1)
...
LOOP
'Loops until end of file number #1.

LINE INPUT #1, s$
's$ = the entire line, after it reads a line it goes to the next one automaticly but doesn't read it yet.

PRINT s$
'I wonder what this does.


What's not to be "comfortable" with? ... - Glenn - 07-12-2003

How does adding more keywords increase comfort? (Personally, when comfort's a problem for *me*, I go out and buy a better chair.) Smile


Thanks - Jsmith - 07-12-2003

Thanks - that works fine


No problem. - Glenn - 07-12-2003

.


Re: What's not to be "comfortable" with? ... - Moneo - 07-13-2003

Quote:How does adding more keywords increase comfort? (Personally, when comfort's a problem for *me*, I go out and buy a better chair.) Smile
Glenn 'ol buddy, I'm not trying to make an issue here. My well intentioned point was in case he normally didn't use WHILE/WEND. You will find that more and more people are no longer using WHILE/WEND and using DO WHILE or LOOP WHILE instead. When they come about a WHILE/WEND in an example, they may not be sure how it works.
*****


Does anyone ever try to start an issue? :) ... - Glenn - 07-13-2003

(What makes you think I was making any sort of accusation? I just asked a question. Smile ) How does one start an issue anyway? Issues exist in and of themselves. It's just a matter of whether anyone sees the issue or not. Smile People may also not understand a DO WHILE loop too. If there's a problem understanding a WHILE/WEND loop, I fail to see how adding more keywords makes things easier to understand. Either way, the solution to not understanding something is to learn about it, not to avoid it. If seeing an example using the structure doesn't help one understand it, I can't see what would. (And if he was more familiar with DO WHILE loops then WHILE/WEND loops, why did the question arise in the first place?) Smile


Opening files - Moneo - 07-14-2003

Ok, Glenn, I get your point --- thanks.
*****