From: Armin Zingler on
Am 09.04.2010 14:18, schrieb Scott:
> I normally do use byval as a default...
>
> Normally the only reasons I use ByRef is either to change something
> like you said, or also if the object is very large like a huge dataset
> or something it seems like a waste to make a copy of it.

You don't make a copy of a Dataset if you pass it ByVal. You make
a copy of the variable content, and that's just the reference (32/64 bits)
to the DataSet.


--
Armin
From: Patrice on
> Normally the only reasons I use ByRef is either to change something
> like you said, or also if the object is very large like a huge dataset
> or something it seems like a waste to make a copy of it.

Objects are pointers. ByVal, ByRef is just about the pointer, not the data
this pointer points to :

Sub ByValTest(ByVal o As SomeObject)
o.MyProperty="A" ' This change will be seen in the main code (access is
done using a copy of the pointer but it still points to the same location)
o=Nothing ' You set the copy of the pointer itself to 0, this change
won't be seen in the main code as you modify a copy of the pointer value
End Sub

Sub ByValRef(ByRef o As SomeObject)
o.MyProperty="B" ' This change will be seen in the main code (access is
done using the pointer and it still points to the same location)
o=Nothing ' Will set also the argument to nothing as here you are
working on the real value of the pointer, not on a copy...
End Sub

ByVal/ByRef doesn't change the behavior when you modify the object data. It
differs only when you change the object variable itself...

--
Patrice












From: Cor Ligthert[MVP] on
And to add to the answer from Armin,

Especially with a dataset you will almost never use the ByRef.

With the dataset it is common practice to use either the Fill or a function
like GetDataset.

The later function creates always a new dataset and returns the reference of
that ByVal, while the Fill fills the dataset which is referenced in the
ByVal.

Cor

"Armin Zingler" <az.nospam(a)freenet.de> wrote in message
news:urE0H8#1KHA.5880(a)TK2MSFTNGP05.phx.gbl...
> Am 09.04.2010 14:18, schrieb Scott:
>> I normally do use byval as a default...
>>
>> Normally the only reasons I use ByRef is either to change something
>> like you said, or also if the object is very large like a huge dataset
>> or something it seems like a waste to make a copy of it.
>
> You don't make a copy of a Dataset if you pass it ByVal. You make
> a copy of the variable content, and that's just the reference (32/64 bits)
> to the DataSet.
>
>
> --
> Armin