Program hangs up because of DOESFILEEXIST()

Previous topic - Next topic

S. P. Gardebiter

If I execute the following code, my program hangs up for whatever reason:

Code (glbasic) Select
LET Config
LET ConfigSaved
LET file$

Config = DOESFILEEXIST("Config.dat")
IF Config
ConfigSaved = TRUE
OPENFILE(1, "Config.dat", TRUE)
READLINE 1, file$
CLOSEFILE 1
GOTO Open
ELSE
ConfigSaved = FALSE
PRINT "Please type exectuable name:", 16, 16
INPUT file$, 16, 32
GOTO Open
ENDIF
~ Cave Story rules! ~

PeeJay

Aaaargh, the curse of GOTO - and what is LET????

Try this:-

Code (glbasic) Select
LOCAL Config,ConfigSaved,file$

Config = DOESFILEEXIST("Config.dat")
IF Config=TRUE
    ConfigSaved = TRUE
    OPENFILE(1, "Config.dat", TRUE)
    READLINE 1, file$
    CLOSEFILE 1
ELSE
    ConfigSaved = FALSE
    PRINT "Please type exectuable name:", 16, 16
    INPUT file$, 16, 32
ENDIF
OpenFunc(ConfigSaved,file$)

FUNCTION OpenFunc: ConfigSaved,file$
.
.
.
ENDFUNCTION
www.peejays-remakes.co.uk
For games, remakes, and GL Basic Tutorials
Artificial Intelligence is no match for Natural Stupidity

S. P. Gardebiter

Ahh yea, much better. Thanks.
So it doesn't work with GOTO?
~ Cave Story rules! ~

PeeJay

GOTO works, but it is horrible! The problem with GOTO is that it breaks up program logic, and can be too easy to get into an endless loop. With this in mind, it is considered very bad practice to use GOTO in code these days.

Happy to help :)

Edit: As you can see by my code edit, it is easy to pass local variables to a function, and is preferable to having loads of GLOBAL variables - again, it makes for neater, self contained code - once you have written your "OpenFunc:" function, you could just copy and paste it into your next project with no need to edit anything ;)
www.peejays-remakes.co.uk
For games, remakes, and GL Basic Tutorials
Artificial Intelligence is no match for Natural Stupidity

bigsofty

Spots a "GOTO"... runs away!,,, :giveup:
Cheers,

Ian.

"It is practically impossible to teach good programming style to students that have had prior exposure to BASIC.  As potential programmers, they are mentally mutilated beyond hope of regeneration."
(E. W. Dijkstra)

Ian Price

I haven't used a GOTO since coding on the CPC, 20 years ago! It has its uses, but to me it's pure evil in code form. :p
I came. I saw. I played.

Kitty Hello

If I have a double nested loop (for x... for y... ) and want to exit from inside,  use goto. Only there.

Moru

*shudder* that would certainly cause troubles with some basic dialects. If you jump out of the nested for...next It would spend the rest of the program searching for the missing nexts :-)

Only time I ever used GOTO was in the same sentence as ON ERROR :-)

Oh, and in assembler when doing just about anything... BEQ or whatever :-)