Difference between revisions of "RUN"

From QB64.org wiki
Jump to: navigation, search
 
(One intermediate revision by the same user not shown)
Line 18: Line 18:
  
 
''Usage:''
 
''Usage:''
* The starting [[line number]] MUST be one used in the main module code! Even with [[SUB]] or [[FUNCTION]] references.  
+
* The starting [[line number]] MUST be one used in the main module code, even if RUN is called from within a SUB or FUNCTION.
 
* If no line number is given the currently loaded program runs from the first executable line.
 
* If no line number is given the currently loaded program runs from the first executable line.
 
* In '''QB64''' RUN can open any kind of executable program and provide case sensitive program specific parameters.  
 
* In '''QB64''' RUN can open any kind of executable program and provide case sensitive program specific parameters.  
* RUN does not return to the calling procedure if the program called is not a Qbasic procedure!
+
** Recommended practice to run external programs is to use [[SHELL]].
* RUN closes all open files and closes the invoking program module before the called program starts. (Cannot use Basica's R)
+
* RUN closes all open files and closes the invoking program module before the called program starts.
* If you do NOT want opened files to be closed use [[CHAIN]] instead.
+
* RUN resets the [[RANDOMIZE]] sequence to the starting [[RND]] function value.
* RUN should reset the [[RANDOMIZE]] sequence to the starting [[RND]] function value.(Not in QB64)
+
* '''Note: Calling RUN repeatedly may cause a stack leak in QB64 if it is called from within a [[SUB]] or [[FUNCTION]]. Avoid when possible.'''
* Note: Qbasic also allowed /RUN in a command line call to run a BAS file with the interpreter. QB64 cannot run BAS files!
 
* '''Note: RUN causes a stack leak in QB64 if it is called from within a [[SUB]] or [[FUNCTION]]. Avoid when possible!'''
 
* '''NOTE: [[Keywords_currently_not_supported_by_QB64#Keywords_Not_Supported_in_Linux_or_MAC_OSX_versions |Not available in Linux or Mac operating systems.]]'''
 
 
 
 
 
''QBasic/QuickBASIC:''
 
* In Qbasic '''/RUN''' can also be used to run a program module in a command line. Example: QB.EXE /L /RUN Module1.BAS
 
  
  
Line 60: Line 53:
 
Do you want to quit?(Y/N)_
 
Do you want to quit?(Y/N)_
 
{{OutputEnd}}
 
{{OutputEnd}}
 
 
''Example 2:'' Compile both programs below with QB64. ProgramA [[RUN]]s ProgramB with a parameter passed following the filename:
 
{{CodeStart}} '            ================ ProgramA.BAS ===================
 
{{Cl|LOCATE}} 12, 36: {{Cl|PRINT}} "ProgramA"
 
 
{{Cl|LOCATE}} 23, 25: {{Cl|PRINT}} "Press any key to run ProgramB"
 
K$ = {{Cl|INPUT$}}(1)
 
{{Cl|RUN}} "ProgramB FS"  'pass FS parameter to ProgramB in QB64 ONLY
 
 
{{Cl|END}} '' ''
 
{{CodeEnd}}
 
: ''ProgramB'' checks for fullscreen parameter pass in QB64 and goes full screen.
 
{{CodeStart}} '            ================ ProgramB.BAS ===================
 
{{Cl|LOCATE}} 12, 36: {{Cl|PRINT}} "ProgramB"
 
parameter$ = {{Cl|UCASE$}}({{Cl|COMMAND$}})
 
{{Cl|LOCATE}} 20, 33: {{Cl|PRINT}} "Parameter = " + parameter$
 
{{Cl|IF...THEN|IF}} {{Cl|LEFT$}}(parameter$, 2) = "FS" {{Cl|THEN}} {{Cl|_FULLSCREEN}} 'parameter changes to full screen
 
 
{{Cl|END}} '' ''
 
{{CodeEnd}}
 
{{OutputStart}}                              Parameter = FS.EXE
 
{{OutputEnd}}
 
: '''Note:''' The above RUN procedure will NOT work in Qbasic! Qbasic cannot pass [[COMMAND$]] parameters with RUN!
 
  
  

Latest revision as of 00:09, 9 February 2020

RUN is a control flow statement that clears and restarts the program currently in memory or executes another specified program.

The multi-modular technique goes back to when QBasic and QuickBASIC had module size constraints. In QB64 it has been implemented so that that older code can still be compiled, though it is advisable to use single modules for a single project (not counting $INCLUDE libraries), for ease of sharing and also because the module size constraints no longer exist.


Syntax

RUN [{line_number | filespec$}] [command_parameter(s)]


Parameters

  • line number specifies a line number in the main module code.
  • An optional filespec specifies a program to load into memory and run.
* BAS or EXE extensions are assumed to be the same as the calling module's extension, EXE or BAS (Qbasic only).
* file names specs with other extensions must use the full filename. No extension requires a dot.
  • In QB64 command line parameters can follow the program file name and be read using the COMMAND$ function later.


Usage:

  • The starting line number MUST be one used in the main module code, even if RUN is called from within a SUB or FUNCTION.
  • If no line number is given the currently loaded program runs from the first executable line.
  • In QB64 RUN can open any kind of executable program and provide case sensitive program specific parameters.
    • Recommended practice to run external programs is to use SHELL.
  • RUN closes all open files and closes the invoking program module before the called program starts.
  • RUN resets the RANDOMIZE sequence to the starting RND function value.
  • Note: Calling RUN repeatedly may cause a stack leak in QB64 if it is called from within a SUB or FUNCTION. Avoid when possible.


Example 1: Shows how RUN can reference multiple line numbers in the main module code. No line number executes first code line.

PRINT " A", " B", " C", " D" 10 A = 1 20 B = 2 30 C = 3 40 D = 4 50 PRINT A, B, C, D 60 IF A = 0 THEN 70 ELSE RUN 20 'RUN clears all values 70 IF B = 0 THEN 80 ELSE RUN 30 80 IF C = 0 THEN 90 ELSE RUN 40 90 IF D = 0 THEN 100 ELSE RUN 50 100 PRINT INPUT "Do you want to quit?(Y/N)", quit$ IF UCASE$(quit$) = "Y" THEN END ELSE RUN 'RUN without line number executes at first code line

A B C D 1 2 3 4 0 2 3 4 0 0 3 4 0 0 0 4 0 0 0 0 Do you want to quit?(Y/N)_


See also:



Navigation:
Go to Keyword Reference - Alphabetical
Go to Keyword Reference - By usage
Go to Main WIKI Page