FAQ By Value or By Reference

Description and exemplification of

  • parameter passing (in, out, in/out)
  • call by reference/value

[kml_flashembed movie="http://www.youtube.com/v/1uTKz7sk37s" width="425" height="344" allowfullscreen="true" fvars="fs=1" /]

ByVal is used for input only parameters, any changes made by the subroutine are not passed back to the original variable. Only the Value is passed.

Private sub DisplayName(byval name as string)

ByRef is used for output parameters, any changes made by the subroutine are made to the original variable. The Memory Reference to the variable is passed.

Private sub getNumber(byref numberA as Integer)

ByVal = Input

By Ref = Output