You can insert this command by simply typing CALLSUB in the edit window and then pressing TAB where you want the command to appear in the Edit window. Once the command is inserted, you will need to specify the subroutine's name, its location if it's in an external part program, as well as any values to pass to available arguments. See "Passing Arguments into a Subroutine" for examples of passing arguments.

1. Select the Insert | Flow Control Command | Call Sub option from the submenu. The Call Subroutine dialog box
   opens. See Understanding the Call Subroutine Dialog Box"" for information on this dialog box.

2. Click the Select Subroutine button. The Select Subroutine dialog box
   opens.

3. Select either the User Directory check box or the Current Directory check box or both. If the part program the subroutine is from resides in the directory specified to be searched for subroutines, select the User Directory check box. If it is from the current directory, mark the Current Directory check box. PC-DMIS lists all the part programs available for selection.

4. Select the part program which contains the subroutine you want. You will see all subroutines associated with the selected program appear in the Subroutine Name box.

5. Select the subroutine you want to call.

6. Click the OK button. The subroutine information you are going to call will appear in the Name and File boxes of the Call Subroutine dialog box.

7. If you want to pass information into the subroutine, click the Add Arg button, and use the Argument Edit dialog box to define arguments and values to pass. See "Understanding the Argument Edit Dialog Box" for information on this dialog box. See "Passing Arguments into a Subroutine" for examples of passing arguments.

8. Click the OK button again and the CALLSUB command will appear in the selected location of the Edit window.

Call Subroutine dialog box

Select Subroutine dialog box

The Edit window command line syntax for calling a subroutine is this:

CS1 =CALLSUB/<Name>, <File>:<Arg1>,<Arg2>,

CS1 = the label ID given to the CALLSUB command.

<Name> = the name of the subroutine to be called.

<File> = the full path way to the part program that contains the subroutine to call. If this field is blank, PC-DMIS will look in the current part program for the subroutine.

<Arg1> = the value to be passed to the first argument in the subroutine. If this field is blank, the default value defined for the first argument in the subroutine will be used instead.

<Arg1> = the value to be passed to the second argument in the subroutine. If this field is blank, the default value defined for the second argument in the subroutine will be used instead. This syntax sample shows only two arguments. Other arguments can be passed if needed to your subroutine

Note: In your CALLSUB command you should keep a set of pointers to all of the objects made for the subroutine so that you can easily refer to them afterwards using the subroutine's ID. For more information on pointers, see "Pointers" in the "Using Expressions and Variables" section.

CS1 =CALLSUB/GET_OPERATOR_INFO,D:\PARTPROGRAMS\V42SUBROUTINETEST.PRG:V1,V2,,

This example CALLSUB command, CS1, calls a subroutine named GET_OPERATOR_INFO located within the part program V42SUBROUTINETEXT.PRG located in the D:\PARTPROGRAMS\ directory. It passes two values—in this case the variables V1 and V2—into the subroutine.

### Calling a Subroutine

To call a subroutine you need to insert a CALLSUB command into your part program to call an existing subroutine from the current part program or a subroutine from an external part program.

Calling a Subroutine by Typing CALLSUB

Calling a Subroutine Using the Call Sub Menu Item

Syntax for the CALLSUB Command

Example CALLSUB Command

More:

Understanding the Call Subroutine Dialog Box

Passing Arguments into a Subroutine

To add a new argument using the Call Subroutine Dialog box:

To edit existing arguments using the Call Subroutine Dialog box:

To delete arguments from a CALLSUB command:

Using CALLSUB Statements in Multiple Arm Mode