Executes a single complete line of BASIC supplied in string-expression in the current program's context.
- The string must form one valid statement line (for example PRINT "Hello", X = 10, PROCdemo).
- On error, ERR$ is set to the error message and ERR is set to 1. Execution then continues at the statement after EVAL.
- Recursive EVAL is not permitted (code running under EVAL may not call EVAL again).
Examples
Print from a generated line
EVAL "PRINT " + CHR$(34) + "Hello from EVAL!" + CHR$(34)
Set a variable dynamically
NAME$ = "COUNT"
EVAL NAME$ + " = 42"
PRINT COUNT
Call a procedure
DEF PROCgreet
PRINT "Greetings"
ENDPROC
EVAL "PROCgreet"
Error handling (ERR/ERR$ set, program continues)
ERR = 0
ERR$ = ""
EVAL "A = 1/0"
IF ERR <> 0 THEN
PRINT "EVAL failed: "; ERR$
ENDIF
Notes
- Provide exactly one statement; statement separators are not supported.
- The evaluated line runs with access to the program's current variables, procedures, and functions.
- Use EVAL for small, dynamic actions. For larger logic, write normal procedures/functions and call them directly.
See also: DEF, PROC, FN, ERR/ERR$