RUN Statement ---------------------------------------------------------------------------- Action Restarts the program currently in memory, or executes a specified program. Syntax RUN { linenumber | filespec$} Remarks The RUN statement uses the following arguments. ----------------------------------------------------------------------------- Argument Description ---------------------------------------------------------------------------- linenumber The numeric label of the line where execution begins. If no argument is given, execution begins at the first executable line of code. filespec$ A string expression that names the program file to load and run. The Argument Description ---------------------------------------------------------------------------- program file to load and run. The current program is cleared from memory before the specified program is loaded. The line where execution begins must be in the module-level code. Therefore, a RUN statement in a SUB or FUNCTION procedure must point to labels at module level. If no line label is given, execution always starts with the first executable line of the main module. Program lines can have line numbers or alphanumeric labels, such as OpenWindow.. If an alphanumeric label is the target of a RUN statement, the compiler generates the error message String expression required. You do not need to specify the filename extension in filespec$. The .BAS extension is assumed in the QBX environment, whereas the .EXE extension is assumed for compiled, stand-alone programs. If the program you wish to run has a different extension, you must give the extension. If the program name has no extension, the filename given must end with a period. For example, the following statement would execute CATCHALL.EXE from a BC-compiled program, and CATCHALL.BAS from within the QBX environment. RUN "CATCHALL" Programs running within the QBX environment must call only BASIC program files. The file is loaded and run as if it were a BASIC program; if it is not in the BASIC program format, execution halts. The error message that results varies, depending on the file's contents. Likewise, programs compiled with the compiler must not invoke BASIC source files, as these run only in the QBX environment. An executable file need not have been written in BASIC. Any executable file can be run. When running a program in the QBX environment, if an executable file matching the filename in the command line cannot be found, BASIC generates the error message File not found and control returns to BASIC. When running a program compiled by BC, BASIC generates the error message File not found in module module-name at address segment.offset and control returns to the operating system. When the invoked program completes execution, control does not return to the invoking program. If the invoking program ran outside QBX, control returns to the operating system. If the invoking program ran under QBX, control returns to BASIC. RUN closes all files and clears program memory before loading the designated program. The compiler does not support the R option from BASICA. (The R option keeps all open data files open.) If you want to run a different program, but leave open files open, use the CHAIN statement. See Also CHAIN Example This example shows how RUN linenumber resets all numeric variables to 0. As the line number following RUN increases in lines 60, 70, 80, and 90, the variables in the earlier statements lose their assigned values. 10 A = 9 20 B = 7 30 C = 5 40 D = 4 50 PRINT A, B, C, D 60 IF A = 0 THEN 70 ELSE RUN 20 70 IF B = 0 THEN 80 ELSE RUN 30 80 IF C = 0 THEN 90 ELSE RUN 40 90 IF D = 0 THEN END ELSE RUN 50 Output 9 7 5 4 0 7 5 4 0 0 5 4 0 0 0 4 0 0 0 0