omron — Subroutines

Subroutines program. Any argument that is to be changed by a subroutine and passed back to the calling routine must be specified as a variable (not an expression or value). In addition to passing variables whose value you want changed, you will also pass variables that are required for the subroutine to perform its task but whose value you do not want changed after the subroutine completes execution. Pass these variables by value. When a variable is passed by value, a copy of the variable, rather than the actual variable, is passed to the subroutine.

The subroutine can make changes to the variable, but the changes are not returned to the calling program (the variable in the calling program has the same value it had when the subroutine was called). The following figure shows how to pass the different types of variables by value. Real numbers and integers are surrounded by parentheses, :NULL is appended to location variables, and +"" is appended to string variables. In the following figure, real_var_b is still being passed by reference, and any changes made in the subroutine will be reflected in the calling program. The subroutine cannot change any of the other variables:

it can make changes only to the copies of those variables that have been passed to it. (It is considered poor programming practice for a subroutine to change any arguments except those that are being passed back to the calling routine. If an input argument must be changed, Omron Adept suggests you make an AUTOmatic copy of the argument and work with the copy.) eV+Language User's Guide, v2.x, 18318-000 Rev A Page 30