LoginLogin
Nintendo shutting down 3DS + Wii U online services, see our post

Problems while trying to make a LOAD/EXEC function on my DOS-like program.

Root / Programming Questions / [.]

the_squat1115Created:
Hi, 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 @MAIN
Notes: 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.

The 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."
ENDIF
FLAG=0
FOR I=0 TO LEN(PROGRAM$)-1
  IF INSTR("0123456789@_-.ABCDEFGHIJKLMNOPQRSTUVWXYZ",PROGRAM$[I])==-1 THEN FLAG=1BREAK
NEXT I
IF FLAG THEN ?"Did you mistype the name or did you type in lowercase?":GOTO @MAIN
EDIT: Made a bit clearer...