Passing Value and Reference Parameters

You might wish to pass a value type to a procedure as a reference with the keyword ByRef. In this case, the data itself is not copied to the stack, but only a pointer to the corresponding storage location in the stack. Changes to other data within the procedure are directly reflected in the original variable. Changing the reference parameters within the called procedure changes the variable value in the calling program, as well. Here’s an example:

Dim ValueType1 as New NumberSystems(10) TakesValueType(ValueType1) Console.WriteLine(ValueType1.Value) Dim ValueType2 as NumberSystems = ValueType1 ValueType2.Value = 50 Console.WriteLine(ValueType1.Value) . . . Sub TakesValueType(ByRef ValueType As NumberSystems) ...

Get Microsoft® Visual Basic® 2010 Developer’s Handbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.