![]() |
|
|||||||||||||||
|
A subroutine is a very useful tool that allows you re-use code without having to write it each time in your program. Subroutines can either be internal or external to a part program. Consider these examples: Example 1: (Construct a square slot using a subroutine) This example contains two part programs and uses a subroutine to construct a generic square slot feature. The first part program contains the subroutine calling statement, and the second part program contains the actual subroutine. Note that the code provided in these examples provides several document (or programmer) comments detailing what's happening in both the calling part program and in the subroutine. The Calling Part ProgramStep 1: First we'll measure four lines that represent the four edges of the slot. Line one will start with one of the long sides, then line two will be a short side, line three will be the second long side, and line four will be the second short side.
Step 2: Next we'll define eight variables, setting each to a value of 0. They will hold the data for the generic square slot that will be constructed. Step 3: Call the subroutine with the CALLSUB statement:
Things to Note:
sales@wilcoxassoc.com
| webmaster@wilcoxassoc.com
|
||||||||||||||||