Defined subroutines can have arguments (sometimes called parameter lists). In the definition of the subroutine they look like this:
Sub MYSUB (arg1, arg2$, arg3)
<statements>
<statements>
End Sub
And when you call the subroutine you can assign values to the arguments.
For example:
MYSUB 23, "Cat", 55
Inside the subroutine arg1 will have the value 23, arg2$ the value of “Cat”, and so on. The arguments act like ordinary variables but they exist only within the subroutine and will vanish when the subroutine ends. You can have variables with the same name in the main program and they will be different from arguments defined for the subroutine (at the risk of making debugging harder).
When calling a subroutine you can supply less than the required number of values.
For example:
MYSUB 23
In that case the missing values will be assumed to be either zero or an empty string. For example, in the above case arg2$ will be set to “” and arg3 will be set to zero. This allows you to have optional values and, if the value is not supplied by the caller, you can take some special action.
You can also leave out a value in the middle of the list and the same will happen.
For example:
MYSUB 23, , 55
Will result in arg2$ being set to “”.
Leave a Reply