qb45advr.hlp (Topic list)
SUB Procedures
  Modules and Procedures   SUB Procedures   Contents   Index
──────────────────────────────────────────────────────────────────────────────
SUB Procedures
 
Unlike DEF FN functions and FUNCTION procedures, SUB is invoked as a
separate statement:
 
  ' Print a message in the middle of the screen.
  CLS
  CALL PrntMsg(12,40,"Hello!")
  END
  ' Print message at the designated row and column.
  SUB PrntMsg(Row%,Col%,Message$) STATIC
    ' Save current cursor position.
    CurRow% = CSRLIN
    CurCol% = POS(0)
    ' Print the message at the location.
    LOCATE Row%,Col% : PRINT Message$;
    ' Restore cursor location.
    LOCATE CurRow%,CurCol%
  END SUB
 
SUB procedures can be used to return multiple values to a calling routine
and are not invoked as part of an expression.
 
All SUB arguments are passed by reference. This allows SUB procedures to
return values by changing variables in the argument list--the only way a
SUB can return a value.
 
You can invoke SUB procedures without the CALL keyword if the SUB is
declared. When you do this, you omit the parentheses that normally
surround the parameter list.
 
  DECLARE SUB PrntMsg (Row%,Col%,Msg$)
  ' Print a message in the middle of the screen.
  CLS
  PrntMsg 12,40,"Hello!"    'Note the missing parentheses.
  END
  .
  .
  .
 
SUB procedures can be used recursively--that is, you can write a SUB
procedure that calls itself.