public sub XByRef(byref a as long)
''a is a reference to the original caller variable
a = a + 10
exit sub
public sub XByVal(byval a as long)
''a is a just a copy of the original caller variable
a = a + 10
exit sub
using byref, the variable 'a' is increased by 10 in the caller scope. Using byval, it remains the same.
dim a as long
a = 10
call XByVal(a)
'' a is still 10
call XByRef(a)
'' a is now 10
Use ByRef if you want that the method can change the value of the variable when it returns.
Marco
|