|
Subject:
|
ByRef and ByVal
|
|
Posted By:
|
kgs51
|
Post Date:
|
11/2/2004 4:16:33 PM
|
Can someone explain the difference between ByRef and ByVal using an example. This would be most appreciated.
|
|
Reply By:
|
marcostraf
|
Reply Date:
|
11/2/2004 6:42:56 PM
|
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
|
|
Reply By:
|
kgs51
|
Reply Date:
|
11/2/2004 7:09:09 PM
|
Marco,
Thankyou very much for the example
|