Problems while trying to make a LOAD/EXEC function on my DOS-like program.
#1✎ 434the_squat1115First YearMy account is over 1 year oldWebsiteForum ContributorHiddenAchievementsIntermediate ProgrammerI can make programs, but I still have trouble here and there. Programming StrengthHi, its been a while since I don't make new forums because of problems while debugging on SmileBASIC.
Its giving me a syntax error on line 38 of my program (after using the "EXEC" command and specifying what file and what type of file to load, it checks if it exists.), however, the program appears to refuse to check if the file exists or its not corrupted.
This is my code:
IF CHKFILE(PROGRAM$)==TRUE THEN EXEC "PRG1:",PROGRAM$ ELSE PRINT "File not found... Please check if specified file exists or check if it isnt corrupted.":GOTO @MAINNotes:
The variable PROGRAM$ is supposed to store the specified program to load.
I'm actually not sure if the variable should go with the semicolon before it.
#2✎ 348CyberYoshi64Intermediate ProgrammerI can make programs, but I still have trouble here and there. Programming StrengthSecond YearMy account is over 2 years oldWebsiteNight PersonI like the quiet night and sleep late.Express YourselfThe PROGRAM$ should be added to the "PRG1:" with a +.
IF CHKFILE(PROGRAM$)==TRUE THEN EXEC "PRG1:"+PROGRAM$ ELSE PRINT "File not found... Please check if specified file exists or check if it isnt corrupted.":GOTO @MAIN
You should also do other checks, such as PROGRAM$'s length being between 1 and 14 (or 32 if used in SB4) and that it contains valid chars to prevent further crashes:
IF LEN(PROGRAM$)<1 || LEN(PROGRAM$)>14 THEN
?"Invalid program name length."
FOR I=0 TO LEN(PROGRAM$)-1
IF INSTR("[email protected]_-.ABCDEFGHIJKLMNOPQRSTUVWXYZ",PROGRAM$[I])==-1 THEN FLAG=1BREAK
IF FLAG THEN ?"Did you mistype the name or did you type in lowercase?":GOTO @MAIN
EDIT: Made a bit clearer...