08-22-2005, 01:55 AM
Is there any way in FB/QB to test for the existence of a file, and have the program simply "move on" if it doesn't exist? That way the whole program doesn't crash from trying to interact with what doesn't exist.
A lighter "File not Found" routine
|
08-22-2005, 01:55 AM
Is there any way in FB/QB to test for the existence of a file, and have the program simply "move on" if it doesn't exist? That way the whole program doesn't crash from trying to interact with what doesn't exist.
08-22-2005, 02:20 AM
My method is to use ON ERROR with OPEN...FOR INPUT -
[syntax="QBasic"]ON ERROR GOTO fileNotFound OPEN "folder\fileName.ext" FOR INPUT AS #1: CLOSE #1 '{program goes here} END 'END must be here unless you want to run your error handling section, even if there are no errors fileNotFound: IF ERR = 53 THEN PRINT "File Not Found. Ending program.": END[/syntax] I hope that helps!
974277320612072617420666C61696C21 (Hexadecimal for those who don't know)
08-22-2005, 07:04 AM
Quote:Is there any way in FB/QB to test for the existence of a file, and have the program simply "move on" if it doesn't exist? That way the whole program doesn't crash from trying to interact with what doesn't exist.Simply "moving on" does not make any sense. What if the only input file to the program does not exist? Got no input, so "move on" to what? The only thing you can do is detect the error, print an error message and terminate the program. That's not exactly "crashing" the program. Crashing it would happen if you don't detect the error, which would send an error number to the screen and abort the program. *****
08-22-2005, 04:04 PM
Quote:Simply "moving on" does not make any sense. What if the only input file to the program does not exist? Got no input, so "move on" to what?Unlike you say, sometimes it is actually the best thing to do, to go on. There are lots of examples to think of.
08-22-2005, 07:41 PM
Unless I'm mistaken.
FB doesn't catch errors unless you compile it with that switch. When it detects and error it sets ERR and moves on. Can't ya just do Code: OPEN "asdd23.txt" FOR INPUT AS #1
08-23-2005, 02:07 AM
From genimplibs.bas (part of FB):
Code: #ifndef FALSE Regards, Mark
08-23-2005, 05:11 AM
Quote:Neo,Moneo Wrote:Simply "moving on" does not make any sense. What if the only input file to the program does not exist? Got no input, so "move on" to what?Unlike you say, sometimes it is actually the best thing to do, to go on. Please give some of these examples. I'm taking about an input data file that the program needs to perform its processing. Not just a little input file that maybe contains the heading that goes on some output report, which obviously can still be generated without the heading. I can't understand what you have in mind. *****
08-23-2005, 05:32 AM
... *looks up at overly complicated examples*
Code: If DIR$(SomePath$+SomeFile$) <> "" Then Exist = 1
08-23-2005, 09:45 AM
If you had some generic stuff that would load in if a file doesn't load, or if the file is extra, then you don't stop everything and bail. 8)
Peace cannot be obtained without war. Why? If there is already peace, it is unnecessary for war. If there is no peace, there is already war."
Visit www.neobasic.net to see rubbish in all its finest. |
« Next Oldest | Next Newest »
|