New errors: next without for and file already open

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
jimbo
Newbie
Posts: 6
Joined: Mon Sep 20, 2010 11:29 am

New errors: next without for and file already open

Post by jimbo »

I have used Qbasic for 15 years and written a ton of programs for scheduling, math, etc. Currently working on a combinatorics problem that was working really well up until yesterday. Suddenly, when attempting to run one of my programs, got a "next without for" error, but the "next" and "for" are clearly there; and got an error in another program of similar structure saying that a "file already open", when trying to open an output file. I've rebooted computer, used task manager to close everything, deleted the so-called already open file, changed file name, moved my programs to another computer with qbasic on it- all to no avail, same errors. I can still run some older programs, eg one which takes a permutation in cycle form and converts into line form, that I wrote just a few days ago. Anyone have any ideas. Please help, as I was looking at the relationship of permutation class structure and number of latin squares of a certain size and hoping to gain insight into same with my programs. Any help greatly appreciated!!
User avatar
burger2227
Veteran
Posts: 2466
Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA

Post by burger2227 »

Next without FOR? Look for a missing END IF

File already OPEN? Look for a file number that may already have been opened for another file. Don't forget to CLOSE a file before using the same #.

CLOSE closes all files. Just type that in the Immediate window and hit enter.
Please acknowledge and thank members who answer your questions!
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0
jimbo
Newbie
Posts: 6
Joined: Mon Sep 20, 2010 11:29 am

Post by jimbo »

Thanks, I already found the next w/out for problem and it's exactly as you said, but in my haste to run the program I guess I thought it had run before after I created some new else, end ifs. I'll try your suggestion for the other one. I may not need to resolve it, since I have the results I need.
Now to make sense of it!
jimbo
Newbie
Posts: 6
Joined: Mon Sep 20, 2010 11:29 am

Post by jimbo »

burger

Tried what you suggested re the file already open. I never use same # for my I/O files and always close them when no longer needed. I did bring up the output screen and saw output that could not have been there from running the program to the point where I got the error as if the program is still trying to write from an earlier time. I've never used the immediate window, but I typed close in it and hit enter, but no luck. I even typed it in the program prior to the offending statement both with and without the number and ran it. I'm thinking of opening a new file and cut and paste all but the offending statement and then entering it in the new program.
jimbo
Newbie
Posts: 6
Joined: Mon Sep 20, 2010 11:29 am

Post by jimbo »

I found the error! Dumb me! I had left the open statement inside a do loop so it was coming back to it and the close statement was outside all the loops, so it was right the file was already open. Funny how computers do what you tell them to do, not what you want them to do. Maybe someone else will benefit from this snafu. Thanks so much again.
User avatar
burger2227
Veteran
Posts: 2466
Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA

Post by burger2227 »

YEP, they are not so smart. You can actually have a computer kill itself LOL.

They ALWAYS do what your code tells them to do! Then when you find the error, it laughs at YOU!

Ted
Please acknowledge and thank members who answer your questions!
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0
Anonymous

Post by Anonymous »

hi burger2227..
thanks for the info you given..
just continue doing good..
thanks a lot and God Bless..

how to treat depression
User avatar
burger2227
Veteran
Posts: 2466
Joined: Mon Aug 21, 2006 12:40 am
Location: Pittsburgh, PA

Post by burger2227 »

Well thankyou Stone, I appreciate the thank you!

If you EVER have a problem, just ask and welcome to the forum. I see you just joined. You can put your location and stuff in your profile if you want.

People come here from all over the world.

Ted

Moderator
Please acknowledge and thank members who answer your questions!
QB64 is a FREE QBasic compiler for WIN, MAC(OSX) and LINUX : https://www.qb64.org/forum/index.php
Get my Q-Basics demonstrator: https://www.dropbox.com/s/fdmgp91d6h8ps ... s.zip?dl=0
Anonymous

Post by Anonymous »

You really do.,thanks for this info.
Share this to others to make some worthy information.

howtodealwithdepression.org
moneo
Veteran
Posts: 451
Joined: Tue Jun 28, 2005 7:00 pm
Location: Mexico City, Mexico

Post by moneo »

Famous last words of a programmer named Fumblefingers:

"My program ran great yesterday, but today it doesn't.
All I changed was only a comment."

Regards..... Moneo
Post Reply