Example of Passing Variables:

This example shows how a variable's value, used as an argument to a subroutine, is modified and passed back from a subroutine:

The variable V1 is assigned the value 6:

ASSIGN/ V1 = 6.

A subroutine call passes V1 as the first argument:

CS1 =CALLSUB/MYSUB,:V1,,,

The subroutine is defined as follows:

SUBROUTINE/MYSUB,

A1 = 0 : FIRST ARGUMENT,

=

ASSIGN/ A1 = A1 + 1

ENDSUB/

A1 is the name for the first argument so when the call is made, A1 will have the same value that V1 did at the time of the call, 6.

The subroutine contains this one statement:

ASSIGN/ A1 = A1 + 1.

This increments the value of A1 to 7.

Then subroutine ends with the ENDSUB/ command.

Flow of execution returns to the statement directly following the CALLSUB command. As execution jumps back, any variables that were used as arguments, V1 in this case, are updated to the value of the corresponding variables in the subroutine, A1 in this case. So, V1 now has a value of 7. The value was passed back from the subroutine.

Example of Passing Number Values:

This example shows how to pass number values into a subroutine. It passes up to two numbers and then adds them together.

CS1 =CALLSUB/SUM_NUMBERS,:,,,

CS2 =CALLSUB/SUM_NUMBERS,:5,10,,

SUBROUTINE/SUM_NUMBERS,

NUM1 = 1 : FIRST NUMBER,

NUM2 = 1 : SECOND NUMBER,

=

COMMENT/OPER,NO,"The sum of the first number, " + NUM1 + ", plus the second number, " + NUM2 + ", is: "

,NUM1 + NUM2

ENDSUB/

In the first CALLSUB command (CS1) no number values are passed into the subroutine. The default numbers, 1 for NUM1 and 1 for NUM2 are used instead, and the generated sum would be 2.

In the second CALLSUB command (CS2) two number values are passed, 5 and 10. So NUM1 would be 5 and NUM2 would be 10, with a generated sum of 15.

Example of Passing Text Strings:

This example shows how to pass string values into a subroutine. It passes two string values into the two parameters and then displays them in the report:

CS1 =CALLSUB/GET_OPERATOR_INFO,:"BOB JONES","MORNING",,

...

SUBROUTINE/GET_OPERATOR_INFO,

OPNAME = <Operator> : OPERATOR NAME,

SHIFT = <Shift> : SHIFT TIME,

COMMENT/REPT,OPNAME

COMMENT/REPT,SHIFT

ENDSUB/

The first argument, OPNAME, receives the passed value of "BOB JONES" and the second argument, SHIFT, receives "MORNING". The COMMENT commands then send the passed strings to the inspection report.

Example of Passing Feature Names:

This example passes in the PNT1 feature name into the subroutine, giving your subroutine complete access to the feature. If no value is passed then the default feature name of F1 is used. This subroutine then queries you for a new value and changes the theoretical X value for the feature.

CS1 =CALLSUB/CHANGE_THEO_X,:{PNT1},,

SUBROUTINE/CHANGE_THEO_X,

FEAT1 = {F1} : PASSED FEATURE NAME,

=

C1 =COMMENT/INPUT,NO,"PASSED FEATURE:"

,FEAT1

,"The current theo X is: " + FEAT1.TX

,"Type a new theo X value:"

ASSIGN/FEAT1.TX = C1.INPUT

COMMENT/OPER,NO,"Feature updated to " + FEAT1.TX

ENDSUB/

Because the subroutine has access to the passed feature, the statement ASSIGN/FEAT1.TX = C1.INPUT modifies the theoretical X value of the actual PNT1 feature. PNT1 will now permanently have its theoretical X value changed.

#### Passing Arguments into a Subroutine

The types of arguments that can be passed into a subroutine are numeric values, variables, text strings, and feature names. To pass values into arguments, type the value within the Value box of the Argument Edit dialog box, or directly into an inserted CALLSUB command in Command mode. See "Creating a New Subroutine" for more details.

Passing Variables into a Subroutine

Arguments that can pass data back are variables. When you use a variable as an argument to a subroutine, any changes that occur to the corresponding variable in the subroutine are passed back and become the value of the variable that was passed in.

Passing Number Values into a Subroutine

Arguments can also take numeric characters.

Passing Text Strings into a Subroutine

Arguments can also take a text string. To pass a text string, make sure the alphanumeric characters are placed within double quotation marks.

Passing Feature Names into a Subroutine

Feature names are passed within curly brackets, for example; {F1} would be used to call the feature designated as F1 into the Edit window. Also, when you pass the feature name, the subroutine has full access to that feature.