Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Opening files
#1
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?
Reply
#2
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.
Reply
#3
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
Reply
#4
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.
[Image: sig.php]
Back by popular demand!
I will byte and nibble you bit by bit until nothing remains but crumbs.
Reply
#5
How does adding more keywords increase comfort? (Personally, when comfort's a problem for *me*, I go out and buy a better chair.) Smile
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.
Reply
#6
Thanks - that works fine
Reply
#7
.
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.
Reply
#8
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.
*****
Reply
#9
(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
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.
Reply
#10
Ok, Glenn, I get your point --- thanks.
*****
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)