EOF

If you have questions about any aspect of QBasic programming, or would like to help fellow programmers solve their problems, check out this board!

Moderators: Pete, Mods

Post Reply
izidor
Veteran
Posts: 110
Joined: Wed Apr 22, 2009 3:13 am
Contact:

EOF

Post by izidor »

When opening a file by typing "open" everything works, but it doesn't work with "print". Can anyone tell me why, it doesn't make any sense to me? :?

Code: Select all

DO
    INPUT a$
    IF a$ = "open" THEN
        INPUT "name:", filename$
        OPEN filename$ FOR INPUT AS #1
        DO WHILE NOT EOF(1)
            INPUT #1, files$
            PRINT files$
        LOOP
        CLOSE #1

    ELSEIF a$ = "print" THEN
        INPUT "name:", filename2$
        OPEN filename2$ FOR INPUT AS #2
        DO WHILE NOT EOF(1)
            INPUT #2, files2$
            PRINT files2$
        LOOP
        CLOSE #2

    END IF
LOOP
User avatar
bongomeno
Veteran
Posts: 266
Joined: Wed Dec 10, 2008 9:08 am
Location: Arizona
Contact:

Post by bongomeno »

what are you trying to do? are you wanting to print to the file?
izidor
Veteran
Posts: 110
Joined: Wed Apr 22, 2009 3:13 am
Contact:

Post by izidor »

No, of course no. I am using that like print command in QB :lol:
moneo
Veteran
Posts: 451
Joined: Tue Jun 28, 2005 7:00 pm
Location: Mexico City, Mexico

Re: EOF

Post by moneo »

izidor wrote:When opening a file by typing "open" everything works, but it doesn't work with "print". Can anyone tell me why, it doesn't make any sense to me? :?

Code: Select all

DO
    INPUT a$
    IF a$ = "open" THEN
        INPUT "name:", filename$
        OPEN filename$ FOR INPUT AS #1
        DO WHILE NOT EOF(1)
            INPUT #1, files$
            PRINT files$
        LOOP
        CLOSE #1

    ELSEIF a$ = "print" THEN
        INPUT "name:", filename2$
        OPEN filename2$ FOR INPUT AS #2
        DO WHILE NOT EOF(1)
            INPUT #2, files2$
            PRINT files2$
        LOOP
        CLOSE #2

    END IF
LOOP
I think the problem is:
OPEN filename2$ FOR INPUT AS #2
DO WHILE NOT EOF(1)

The DO WHILE should be EOF(2)

Regards.
izidor
Veteran
Posts: 110
Joined: Wed Apr 22, 2009 3:13 am
Contact:

Post by izidor »

Yeah that was the problem, thanks, I don't know what would I do if there weren't for this forum!
Post Reply