Hi,
What is ByVal & ByRef(VB)?
Very thans,:)
Printable View
Hi,
What is ByVal & ByRef(VB)?
Very thans,:)
ByVal and ByRef are modifiers used in function parameters.
ByVal means "pass by value". Marking a parameter to be passed by value means that a copy of it is made and passed to the function. The function can modify it, but it won't affect the original variable.
ByRef means "pass by reference" and is the default mode. Passing a variable by reference means that instead of a copy of the variable, the function receives a reference to it. It thus may modify the original variable.
When calling a function with ByRef parameters, you may explicitly specify the ByVal modifier on any of the arguments that you send it. This will force a copy of the variable to be made. You cannot, however, explicitly specify ByRef on a ByVal parameter.
You should also note the behaviour of ByVal with objects. Since object variables are all references anyway, specifying ByVal on these means that a copy of the reference is made, not a copy of the object. Your original reference is safe, but the function can still modify members of the object itself.
Very thanks Penagate ;)