A parameter declared with a ByRef
modifier is a reference parameter. If the ByRef
modifier is specified, the ByVal
modifier may not be used. A reference parameter does not create a new storage location. Instead, a reference parameter represents the variable given as the argument in the method or constructor invocation. Conceptually, the value of a reference parameter is always the same as the underlying variable.
It is important to note that Visual Basic 7.0 may use copy-in/copy-out semantics when passing a variable to a reference parameter. In general, this happens when there is either no storage location to pass a reference to (for example, the argument is a property), or when the type of a storage location is not the same as the parameter type (for example, passing an instance of a base class to a byref derived class parameter). Thus, a reference parameter may not necessarily contain a reference to the exact storage of the variable, and any changes to the reference parameter may not be reflected in the variable until the method exits.