Posts: 2
Threads: 1
Joined: Jul 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?
Posts: 704
Threads: 0
Joined: Dec 2002
OPEN "file.txt" FOR INPUT AS #1
WHILE NOT EOF(1)
LINE INPUT #1, s$
PRINT s$
WEND
CLOSE
ravelling Curmudgeon
(geocities sites require copying and pasting URLs.)
I liked spam better when it was something that came in a can.
Windows should be defenestrated.
Posts: 1,956
Threads: 65
Joined: Jun 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
Posts: 2,765
Threads: 138
Joined: Nov 2002
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.
Back by popular demand!
I will byte and nibble you bit by bit until nothing remains but crumbs.
Posts: 704
Threads: 0
Joined: Dec 2002
How does adding more keywords increase comfort? (Personally, when comfort's a problem for *me*, I go out and buy a better chair.)
ravelling Curmudgeon
(geocities sites require copying and pasting URLs.)
I liked spam better when it was something that came in a can.
Windows should be defenestrated.
Posts: 2
Threads: 1
Joined: Jul 2003
Posts: 704
Threads: 0
Joined: Dec 2002
.
ravelling Curmudgeon
(geocities sites require copying and pasting URLs.)
I liked spam better when it was something that came in a can.
Windows should be defenestrated.
Posts: 1,956
Threads: 65
Joined: Jun 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.)
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.
*****
Posts: 704
Threads: 0
Joined: Dec 2002
(What makes you think I was making any sort of accusation? I just asked a question.
) 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.
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?)
ravelling Curmudgeon
(geocities sites require copying and pasting URLs.)
I liked spam better when it was something that came in a can.
Windows should be defenestrated.
Posts: 1,956
Threads: 65
Joined: Jun 2003
Ok, Glenn, I get your point --- thanks.
*****