RETURN can be used with ASSIGN to test whether the ASSIGN operation was successful. If not successful, the error number is returned in the variable specified, otherwise a zero is returned. The following example shows one possible use for this feature: ASSIGNing a file, but creating the file only if it does not exist:
INTEGER Result
F$="KAREN.TXT"
REPEAT
ASSIGN @I TO F$;RETURN Error
IF Error THEN
IF Error=56 THEN
PRINT "File not found: creating ";F$
CREATE F$,10
ELSE
CAUSE ERROR Error ! Let the error occur
END IF
END IF
UNTIL NOT Error
END
|