Qbasicnews.com
July 09, 2020, 11:59:46 PM *
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] 2
  Print  
Author Topic: "Open" Problem  (Read 7562 times)
Liquid Snake
Wandering Guru
***
Posts: 354



WWW
« on: March 01, 2005, 03:35:13 PM »

Here's a portion of code for a game I'm making.  I keep getting an error "input past end of file"

Code:

LOAD:
PRINT "not done yet"
CHOICE = 0
OPEN "fballsav.txt" FOR INPUT AS #1
WHILE NOT EOF(1)
INPUT #1, qb, kicker, seasons, TOTALWON, TOTALLOST, WON, LOST, NAME$, TRAIN
WEND
CLOSE
RETURN

SAVE:
PRINT "NOT DONE YET"
CHOICE = 0
OPEN "fballsav.txt" FOR OUTPUT AS #1
PRINT #1, qb, kicker, seasons, TOTALWON, TOTALLOST, WON, LOST, NAME$, TRAIN
CLOSE
RETURN
Logged

Not yet Snake! It's not over yet!
TheDarkJay
I hold this place together
*****
Posts: 913



WWW
« Reply #1 on: March 01, 2005, 04:02:16 PM »

{DOUBLE POST}(SORRY)
Logged

url=http://www.sloganizer.net/en/][/url]
TheDarkJay
I hold this place together
*****
Posts: 913



WWW
« Reply #2 on: March 01, 2005, 04:03:24 PM »

The info is not there for you to load, if you have a txt file with not as many numbers as there are there, it will not work.
Logged

url=http://www.sloganizer.net/en/][/url]
Liquid Snake
Wandering Guru
***
Posts: 354



WWW
« Reply #3 on: March 01, 2005, 05:37:17 PM »

That doesn't seem to be the case, because I have 9 variables and 9 values in my save file.  Here's what it looks like:

50          50        0          0           0        0        0     name       0
Logged

Not yet Snake! It's not over yet!
Mitth'raw'nuruodo
Ancient Guru
****
Posts: 515



WWW
« Reply #4 on: March 02, 2005, 01:22:12 AM »

I think It's the loop.

try:
DO
IF EOF(1) = -1 THEN EXIT DO
INPUT #1, blah blah blah
LOOP

That will work as long as the txt file is correct which you said ot was.
Logged

i]"But...it was so beautifully done"[/i]
Neo
Na_th_an
*****
Posts: 2150



« Reply #5 on: March 03, 2005, 06:54:48 AM »

NAME is a restricted variable name.

#1. Try using something different, like playername$
#2. Make sure the playername$ doesn't contain commas, semicolons or spaces.

Just some hints though, because I'm not able to test it atm Smiley
Logged
Anonymous
Guest
« Reply #6 on: March 03, 2005, 08:31:39 AM »

learn binary =P
Logged
barok
Na_th_an
*****
Posts: 1727


How about a tasty lead sandwich?


« Reply #7 on: March 03, 2005, 10:47:15 AM »

i think your problem is your while loop.  It loops, then when it reaches the end of file it loops once more.  Unfortunately, it has nothing else to read, so you got your error.  use a do-loop, or use LOF() to find the length of the file, then run a for...next loop.
Logged

Jumping Jahoolipers!
Neo
Na_th_an
*****
Posts: 2150



« Reply #8 on: March 03, 2005, 06:14:51 PM »

WHILE NOT EOF should work fine.
Logged
pr0gger
I hold this place together
*****
Posts: 775


« Reply #9 on: March 03, 2005, 06:19:52 PM »

[syntax="qbasic"]OPEN "fballsav.txt" FOR INPUT AS #1
WHILE NOT EOF(1)
INPUT #1, qb, kicker, seasons, TOTALWON, TOTALLOST, WON, LOST, NAME$, TRAIN
WEND
CLOSE[/syntax]

I think your problem his here as well, but not necessarily with the WHILE loop.  Since the "EOF" statement is at the top, it should evaluate that everytime it restarts the loop-- so if it reaches the end of the file, it should simply stop.  I think your problem somewhere within the input statement:

[syntax="qbasic"]INPUT #1, qb, kicker, seasons, TOTALWON, TOTALLOST, WON, LOST, NAME$, TRAIN[/syntax]

What may be happening is you might have a file that looks like this:

Code:
50 50 0 0 0 0 0 name 0



With an extra blank line at the end of the file.  If there is one, delete it.

If that doesn't work, try adding commas so your file looks like this:

Code:
50,50,0,0,0,0,0,"name",0


You'll still get the same result, but it should be easier to work with.

Good luck!

--j_k
Logged

size=9]"To announce that there must be no criticism of the president, or that we are to stand by the president, right or wrong, is not only unpatriotic and servile, but is morally treasonable to the American public." -- Theodore Roosevelt[/size]
Ralph
Ancient Guru
****
Posts: 544


« Reply #10 on: March 03, 2005, 09:37:33 PM »

As one final suggestion, just after your line:

INPUT #1, qb, kicker, seasons, TOTALWON, TOTALLOST, WON, LOST, NAME$, TRAIN

add this one:

PRINT "qb =";qb;", kicker =";kicker;", seasons =";seasons";", TOTALWON =";TOTALWON;", LOST =";LOST;", NAME$ = ";NAME$;", TRAIN=";TRAIN

Now, you can see where your problem begins, so you can do whatever correction your probgram requires!  Good luck.
Logged

Ralph, using QuickBASIC 4.5 and Windows XP Home Edition and Service Pack 2, with HP LaserJet 4L printer.
Liquid Snake
Wandering Guru
***
Posts: 354



WWW
« Reply #11 on: March 04, 2005, 04:02:46 PM »

Thanks, I'll give it a try when I get a chance.
Logged

Not yet Snake! It's not over yet!
Liquid Snake
Wandering Guru
***
Posts: 354



WWW
« Reply #12 on: March 05, 2005, 06:15:08 PM »

Changing the variable "name$" didn't make any difference.
The loop doesn't seem to be the problem either.
Logged

Not yet Snake! It's not over yet!
Liquid Snake
Wandering Guru
***
Posts: 354



WWW
« Reply #13 on: March 05, 2005, 06:54:33 PM »

Quote from: "Ralph"
As one final suggestion, just after your line:

INPUT #1, qb, kicker, seasons, TOTALWON, TOTALLOST, WON, LOST, NAME$, TRAIN

add this one:

PRINT "qb =";qb;", kicker =";kicker;", seasons =";seasons";", TOTALWON =";TOTALWON;", LOST =";LOST;", NAME$ = ";NAME$;", TRAIN=";TRAIN

Now, you can see where your problem begins, so you can do whatever correction your probgram requires!  Good luck.



I can't right after that line because the problem comes up ON THAT LINE, so it doesn't go past it.
Logged

Not yet Snake! It's not over yet!
Liquid Snake
Wandering Guru
***
Posts: 354



WWW
« Reply #14 on: March 05, 2005, 07:06:15 PM »

Quote from: "pr0gger"
[syntax="qbasic"]What may be happening is you might have a file that looks like this:

Code:
50 50 0 0 0 0 0 name 0



With an extra blank line at the end of the file.  If there is one, delete it.

If that doesn't work, try adding commas so your file looks like this:

Code:
50,50,0,0,0,0,0,"name",0


You'll still get the same result, but it should be easier to work with.

Good luck!

--j_k


How do you input commas into the file?
Logged

Not yet Snake! It's not over yet!
Pages: [1] 2
  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!