If I execute the following code, my program hangs up for whatever reason:
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
Aaaargh, the curse of GOTO - and what is LET????
Try this:-
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
Ahh yea, much better. Thanks.
So it doesn't work with GOTO?
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 ;)
Spots a "GOTO"... runs away!,,, :giveup:
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
If I have a double nested loop (for x... for y... ) and want to exit from inside, use goto. Only there.
*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 :-)