advr.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 Statement Details
  Summary  Details  Example                Contents  Index  Back
──────────────────────────────────────────────────────────────────────────────
 [STATIC] SUB globalname ([parameterlist])
      [statementblock]
      [EXIT SUB]
      [statementblock]
 END SUB
 
 Usage Notes
   ■ SUB and END SUB mark the beginning and end of a SUB procedure. You can
     use the optional EXIT SUB statement to exit a SUB from any point within
     the procedure.
 
   ■ STATIC indicates that the values of a SUB's local variables are saved
     between calls. Without STATIC, the local variables are allocated each
     time the SUB is invoked, and the variables' values are lost when the
     SUB returns to the calling program.
 
   ■ Using the STATIC attribute increases execution speed slightly.
 
   ■ The STATIC attribute does not affect variables that are used in a SUB,
     but declared outside the SUB in DIM or COMMON statements using the
     SHARED statement.
     See: COMMON Statement  DIM Statement  SHARED Statement
 
   ■ The SUB name cannot appear in any other SUB or FUNCTION statement in
     the same application unless the SUB is in form code. Code within a form
     module is known only to the procedures in that module.
 
   ■ BYVAL can be used only with simple numeric types (INTEGER, LONG, SINGLE,
     DOUBLE, or CURRENCY). The additional types, FORM and CONTROL, can only
     be used when a form or control is passed as an argument to a SUB or
     FUNCTION procedure.
 
   ■ Unless identified with the BYVAL keyword, individual arguments are
     passed by reference, so any change to an argument's value inside the
     SUB procedure changes its value in the calling procedure.
 
   ■ If a parameter is passed by reference, any change to the parameter's
     value inside the procedure changes its value in the calling program.
 
   ■ If no value is assigned to the SUB name, the procedure returns a default
     value: A numeric value returns zero; a string function returns the null
     string ("").
 
   ■ A SUB can be recursive - that is, it can call itself to perform a given
     task. The STATIC keyword is usually not used with recursive SUB
     procedures.
 
   ■ Any SUB procedure variables or arrays are considered local to that SUB
     procedure, unless they are explicitly declared as shared variables in a
     SHARED statement. See: SHARED Statement
 
   ■ Avoid using I/O statements in a SUB procedure called from an I/O
     statement; they can cause unpredictable results. Also, because Visual
     Basic may rearrange arithmetic expressions to attain greater efficiency,
     avoid using SUB procedures that change program variables in arithmetic
     expressions.
 
   ■ A SUB procedure is a separate procedure, like a FUNCTION procedure. It
     can accept arguments, perform a series of statement, and change the
     values of its arguments. However, unlike a FUNCTION procedure, which
     returns a value, a SUB procedure cannot be used in an expression.
     See: FUNCTION Statement
 
   ■ SUB procedures are called by a CALL statement or by using the SUB
     procedure name followed by the argument list.
     See: CALL Statement (Basic Procedures)
 
   ■ Any SUB procedure variables or arrays are considered local to that SUB
     procedure, unless they are explicitly declared as shared variables in a
     SHARED statement.
 
   ■ When you call the SUB procedure, you can specify that an argument's
     value not be changed by the procedure by enclosing the argument in
     parentheses.
 
   ■ You cannot use GOSUB, GOTO, or RETURN to enter or exit a SUB procedure.
 
   ■ You cannot use an array of fixed-length strings as an argument when
     calling a SUB procedure because Visual Basic converts a simple fixed-
     length string argument to a variable-length string argument before
     passing the string to a SUB procedure.