qb45advr.hlp (Topic list)
Important Notice
The pages on this site contain documentation for very old MS-DOS software, purely for historical purposes. If you're looking for up-to-date documentation, particularly for programming, you should not rely on the information found here, as it will be woefully out of date.
SUB...END SUB Statement Details
  QuickSCREEN      Details      Example      Contents      Index
──────────────────────────────────────────────────────────────────────────────
SUB...END SUB Statement Details
 
Syntax
  SUB globalname[parameterlist][STATIC]
    [statements]
  [EXIT SUB]
    [statements]
  END SUB
 
  Argument        Description
  globalname      A variable name up to 40 characters long. This name
                  cannot appear in any other FUNCTION or SUB
                  statement in the same program or the user library.
 
  parameterlist   Contains the names of simple variables and arrays
                  passed to the subprogram when the SUB is invoked.
                  Each name is separated from the preceding name by
                  a comma. Note that these variables and arrays are
                  passed by reference, so any change to an argument's
                  value in the subprogram also changes its value in
                  the calling program. See below for a complete
                  description of the syntax.
 
A SUB parameterlist has the following syntax:
 
  variable[()] [AS type][, variable[( )] [AS type]]...
 
  ■ A variable is a BASIC variable name. Previous versions of BASIC
    required the number of dimensions in parentheses after an array name.
    In QuickBASIC, the number of dimensions is not required.
  ■ The argument type is the type of the variable. The type argument can be
    INTEGER, LONG, SINGLE, DOUBLE, STRING, or a user-defined type. You may
    not use a fixed-length string, or an array of fixed-length strings, as a
    parameter. However, you may use a simple fixed-length string as an
    argument in a CALL statement-QuickBASIC converts a simple fixed-length
    string argument to a variable-length string argument before passing
    the string to a SUB.
 
A subprogram is a separate procedure, like a FUNCTION. However,
unlike a FUNCTION, a SUB cannot be used in an expression.
 
SUB and END SUB mark the beginning and end of a subprogram. You may
also use the optional EXIT SUB statement to exit a subprogram.
 
Subprograms are called by a CALL statement or by using the subprogram name
followed by the argument list. See the entry for the CALL statement.
 
QuickBASIC subprograms can be recursive--they can call themselves
to perform a given task.
 
The  STATIC attribute indicates that all variables local to the SUB
are STATIC--their values are saved between calls. Using the STATIC
keyword slightly increases execution speed. STATIC is not usually
used with recursive subprograms.
 
Any subprogram variables or arrays are considered local to that sub-
program, unless they are explicitly declared as shared variables in
a SHARED statement.
 
You cannot define SUB procedures, DEF FN functions, or FUNCTION
procedures inside a SUB procedure.
 
  Note: You cannot use GOSUB, GOTO, or RETURN to enter or exit a
        subprogram.