Updated: 11/30/2021, 7:00:45 PM
Created: 11/30/2021, 7:00:45 PM
Last Updated By: Jake Tuttle
Read Time: 2 minute(s)

# Description

The SUBROUTINE statement is used at the start of any program that will be called externally by the CALL statement. It also declares any parameters to the compiler. It takes the general form:

SUB{ROUTINE} Name {({MAT} variable{,{MAT} variable...})}


Name is the identifier by which the subroutine will be known to the compilation process. It should always be present as this name (not the source file name), will be used to call it by. However, if the name is left out, the compiler will name subroutine as the source file name (without suffixes). Default naming is not encouraged as it can cause problems if source files are renamed.

Each comma separated variable in the optional parenthesized list is used to identify parameters to the compiler. These variables will be assigned the values passed to the subroutine by a CALL statement.

The SUBROUTINE statement must be the first code line in a subroutine.

A subroutine will inherit all the variables declared using the COMMON statement providing an equivalent COMMON area is declared within the SUBROUTINE source file. The program will fail to compile if the number of common variables used in each common area exceeds the number defined in the equivalent area in the main program.

Subroutines can only be called via the jBASE BASIC CALL statement.

A subroutine can redefine PRECISION but the new precision will not persist when the subroutine returns to the calling program.

A subroutine will return to the CALLing program if it reaches the logical end of the program or a RETURN is executed with no outstanding GOSUB statement.

A SUBROUTINE will not return to the calling program if a STOP or ABORT statement is executed.

An example of use is as:

SUBROUTINE DialUp(Number, MAT Results)
DIM Results(8)


Go back to jBASE BASIC

Go back to Programmers' Reference Guide