A subroutine is a user-defined command that can be called to perform a block of logic, and optionally to return a value. Subroutines are normally used when the same set of statements is repeated in multiple places, such as at multiple activities. In this case, calling the same subroutine from each activity simplifies the logic and provides a single source where the logic can be modified. A subroutine may be named any unique, valid name.
A subroutine may have parameters that act as local variables inside the subroutine and that take the values of the arguments (i.e., numeric expressions) that are passed to the subroutine. Additionally, a subroutine can return either an integer value or a real value to the logic or property field that called the subroutine.
Note: arguments, parameters, and return values are subroutine features available only in the Professional edition of Process Simulator.
Subroutines are defined through the use of the Model Elements dialog, which is accessible from the Advanced Elements button in the Model Elements portion of the Process Simulator ribbon.
Process Simulator handles subroutines in two ways. First, a subroutine may be processed by the calling logic as though the subroutine is part of the calling logic. This is the manner in which a subroutine is most commonly used. When a subroutine in encountered in logic, Process Simulator executes the statements contained in the subroutine directly inline with the logic from where it is called. All logic before a subroutine is executed before the subroutine's logic. All logic after a subroutine is executed after the subroutine's logic has finished. Execution of a subroutine is accomplished by simply referencing the subroutine by name in some logic or expression.
Second, a subroutine may be processed independently of the calling logic so the calling logic continues without waiting for the subroutine to finish. This method requires an ACTIVATE statement followed by the name of the subroutine.
The general format for calling a subroutine without arguments is:
SubroutineName()
The general format for calling a subroutine with arguments is:
SubroutineName(arg1,arg2, ... ,argn)
where arg1 is the name of the first argument, arg2 is the name of the second argument, and argn is the name of the nth argument.
© 2016 ProModel Corporation • 556 East Technology Avenue • Orem, UT 84097 • Support: 888-776-6633 • www.promodel.com