Skip to content

Passing Arguments "By Reference"

Previously, you could only pass arguments "by value," meaning that a copy of a variable was sent to a function, and the function was incapable of modifying the original variable. You can now pass variables "by reference". When a parameter is passed "by reference," the called procedure or function has direct read/write access to the passed variable. Changes made to the reference parameter inside the method are reflected in the passed variable outside the method.

This technique is often applied when there’s a need for multiple return values or for in-out parameters, which pass one value to the called method and are allowed to be modified to contain a different value when the execution returns to the caller. The latter is commonly used in COM event methods as a means of allowing the client code to cancel or modify a certain action or default behavior. In this case, the COM object might pass on a Boolean parameter bCancel, which the program may set to True in order to cancel the pending action.