Richard,
As the others have suggested, you are misunderstanding Value & Reference
Parameters when used with Value & Reference Types!
A Class is a Reference Type, only a single instance of an object exists on
the heap, when pass a Class variable ByVal a copy of the reference is made,
hence the variable & parameter both refer to the same object, allowing your
routine to make changes to the object itself.
Remember there are two types of Parameters (ByRef & ByVal) and there are two
types of variables (Reference Types & Value Types).
So you can have:
ByRef - Reference Type
ByRef - Value Type
ByVal - Reference Type
ByVal - Value Type
Lets look at types of variables:
When you define a Class you are defining a Reference Type. Which means that
a variable of this Class holds a reference to the object, the object itself
exists on the heap. If I assign this variable to a second variable a copy of
this reference is made and I now have two references to the same object on
the heap. There is still only one object on the heap. If you define a
Structure you are defining a Value Type. The variable itself holds the value
of the structure. If I assign this variable to a second variable a copy of
the entire structure is made. I now have two copies of the same structure.
Value Types include:
Boolean, Byte, Short, Integer, Long, Char, Single, Double, Decimal, along
with anything defined with the Structure or Enum keyword.
Value Types all derive directly or indirectly from System.ValueType
Reference Types include:
Object, and anything defined with the Class, Interface or Delegate keyword
are reference types.
Reference Types all derive from System.Object excluding types that inherit
from System.ValueType
Interface is a reference type, even if defined in a Structure. The structure
itself is a value type, however if you assign the structure to a Interface
variable, it will be Boxed, boxing places the value on the heap in a new
object (effectively making it a reference type)
Lets look at types of parameters:
Now when you define a parameter to be ByVal a copy of the variable is
passed. Remember Reference types hold a reference to the object, so passing
a Reference Type ByVal causes a copy of this reference to be passed as a
parameter, the single copy of the object itself is still on the heap. The
variable & parameter both have references to this single object. Passing a
Value Type ByVal causes a complete copy of the value to be passed as a
parameter. Now passing a Reference Type ByRef, causes a reference to the
variable to be passed, the variable has a reference to the object. Passing a
Value Type ByRef also causes a reference to the variable to be passed, the
variable has a copy of the Value.
Remember ByVal & ByRef are how parameters are passed. Reference & Value
Types are how quantities are stored.
Although the following is in C# the concepts apply equally to VB.NET:
http://www.yoda.arachsys.com/csharp/parameters.html
Hope this helps
Jay