[next] [previous] [contents]

  13.1 BASIC Subprograms
  BASIC has SUB, FUNCTION, and PICTURE subprograms.
  Each of these subprograms receives parameters and can
  modify parameters passed by reference or by descriptor.
  The differences between SUB, FUNCTION, and PICTURE
  subprograms are as follows:

  .
        FUNCTION subprograms must be declared with an
        EXTERNAL statement in the calling program. Declaring
        SUB and PICTURE subprograms is optional.
  .
        FUNCTION subprograms return a value; SUB and
        PICTURE subprograms do not return a value.
  .
        PICTURE subprograms must be invoked with the DRAW
        statement and are reserved for use with BASIC graphics.
        For more information about PICTURE subprograms, see
        Programming with VAX BASIC Graphics
.

  All subprograms invoked by a BASIC program must have
  unique names. A BASIC program cannot have different
  subprograms with the same identifiers.

  Subprograms can return a value to the calling program with
  parameters. You can use subprograms to separate routines
  that you commonly use. For example, you can use subpro-
  grams to perform file I/O operations, to sort data, or for table
  lookups.

  You can also use subprograms to separate large programs
  into smaller, more manageable routines, or you can sep-
  arate modules that are modified often. If all references to
  system-specific features are isolated, it is easier to trans-
  port the program to a different system. OpenVMS System
  Services and OpenVMS Run-Time Library routines are spe-
  cific to OpenVMS systems; therefore, you should consider
  isolating references to them in subprograms.
Chapter 20 de-
  scribes how to access Run-Time Library routines and system
  services from BASIC.

  You should also consider isolating complex processing al-
  gorithms that are used commonly. If complex processing
  routines are isolated, they can be shared by many programs
  while the complexity remains hidden from the main program
  logic. However, they can share data only if the following is
  true:

  .
        Data is passed as a parameter from the CALL statement
        or function invocation to the subprogram-see
Section 13.2
        for more information.
  .
        Data is part of a MAP or COMMON block-see Chapter 7
        for information about using MAP and COMMON state-
        ments.
  .
        Data is in a file-see Chapter 14 for more information
        about accessing data from a file.

  All DATA statements are local to a subprogram. Each time
  you call a subprogram, BASIC positions the data pointer at
  the beginning of the subprogram's data.

  The data pointer in the main program is not affected by
  READ or RESTORE statements in the subprogram (in con-
  trast with the RESTORE # statement, which resets record
  pointers to the first record in the file no matter where it is
  executed).
Chapter 6 contains more information about the
  READ and RESTORE statements. For more information
  about the RESTORE # statement, see Chapter 14.