Qbasicnews.com
March 21, 2019, 06:40:51 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 6600 times)
Liquid Snake
Wandering Guru
***
Posts: 354



WWW
« Reply #15 on: March 05, 2005, 07:21:37 PM »

Quote from: "Mitth'raw'nuruodo"
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.


Unfortuanately, that wasn't the case either
Logged

Not yet Snake! It's not over yet!
Ralph
Ancient Guru
****
Posts: 544


« Reply #16 on: March 05, 2005, 07:38:05 PM »

Quote from: "Liquid Snake"
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.


O.K., then, try dissecting your INPUT and PRINT statements:

INPUT #1, qb:PRINT "qb =";qb
INPUT#1, kicker:PRINT "kicker =";kicker
etc.

Now, you should be able to see at what point the INPUT has a problem.
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 #17 on: March 05, 2005, 08:05:46 PM »

ok I'll give it a try, but I'm open to any other suggestions as well.
Would I still need the loop if I try what you suggested?

By the way, is the OPEN statement the easiest way to do this? Or is there a better way?
Logged

Not yet Snake! It's not over yet!
Ralph
Ancient Guru
****
Posts: 544


« Reply #18 on: March 05, 2005, 08:39:51 PM »

Quote from: "Liquid Snake"
ok I'll give it a try, but I'm open to any other suggestions as well.
Would I still need the loop if I try what you suggested?

By the way, is the OPEN statement the easiest way to do this? Or is there a better way?

Yes, you will maintain all your code just as it is, except for modifying the INPUT #1 statement to only one entry at a time, followed by the addition of a PRINT statement with the expected entry, so you can see at which point the problem begins.  Me, I am only trying to help you find the problem you have.
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 #19 on: March 05, 2005, 08:41:20 PM »

Quote from: "Ralph"
Quote from: "Liquid Snake"
ok I'll give it a try, but I'm open to any other suggestions as well.
Would I still need the loop if I try what you suggested?

By the way, is the OPEN statement the easiest way to do this? Or is there a better way?

Yes, you will maintain all your code just as it is, except for modifying the INPUT #1 statement to only one entry at a time, followed by the addition of a PRINT statement with the expected entry, so you can see at which point the problem begins.  Me, I am only trying to help you find the problem you have.


The problem occurs at the last variable.
Logged

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



WWW
« Reply #20 on: March 05, 2005, 09:18:02 PM »

I know what the problem is now. The last variable is being read as part of the second to last variable. So, I made the string the last variable,   the problem is gone.  However, how can I avoid this problem, say if there is  a string variable after another a string variable.
Logged

Not yet Snake! It's not over yet!
Ralph
Ancient Guru
****
Posts: 544


« Reply #21 on: March 06, 2005, 12:50:15 AM »

Just make sure you have a comma (,) immediately after each  string variable, as for this data file containing 5 digits and 2 strings:

1 2 3 4A, 5 6B, 7

For numbers, a space is OK, as is a comma.  So, this data could also be written as:

1,2,3,4A,5,6B,7

To write this file in QuickBASIC, you would use:

OPEN "Test1.txt" FOR OUTPUT AS #1
  PRINT #1, 1; 2; 3;"4A"; ","; 5; "6B"; ","; 7
CLOSE #1

which will write a file that looks like this:
1 2 3 4A , 5 6B , 7

As a matter of principal and consistancy, you might just write ALL your data files with comma separators, thus:

OPEN "Test1.txt" FOR OUTPUT AS #1
  PRINT #1, 1; ","; 2;","; 3;",";"4A"; ","; 5;","; "6B"; ","; 7
CLOSE #1

This will write a file that looks like this:

1 , 2 , 3 , 4A , 5 , 6B , 7
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 #22 on: March 06, 2005, 12:53:43 AM »

OK, thanks for all the help.
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!