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 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.