|
我们一般会在下面第二个容易掉进陷井!
Sub testFuns()
Dim lngRet As Long, varLong As Long
varLong = 1
fun1 varLong
Debug.Print varLong
varLong = 1
fun1 (varLong)
Debug.Print varLong
varLong = 1
Call fun1(varLong)
Debug.Print varLong
varLong = 1
Call fun1((varLong))
Debug.Print varLong
varLong = 1
Call fun1(lng:=varLong)
Debug.Print varLong
varLong = 1
Call fun1(lng:=(varLong))
Debug.Print varLong
End Sub
Function fun1(ByRef lng As Long) As Integer
lng = 1000
End Function
输出得到:
1000
1
1000
1
1000
1
应该都看出来了吧,答案:
不管[Sub][Function],如果对参数变量加了括号,即使过程参数是传址,也会将参数作为传值(参数复本传入过程)
如果还不理解,将fun1改为两个参数(其他稍作修改)再运行,你就会彻底明白
Function fun1(ByRef lng As Long,lng2 As Long) As Integer
lng = 1000
lng2=2000
End Function
|
|