2011-06-27 56 views
0

我想通過引用測試通過,並通過值訪問,但它不起作用。通過引用在VBA中不起作用

Sub passByRef(ByRef a As Integer) 
    a = a + 1 
End Sub 
Sub passByVal(ByVal a As Integer) 
    a = a + 1 
End Sub 

Private Sub cmdByRef() 
    Dim i as Integer 
    i = 10 
    passByRef i 
    MsgBox i 
End Sub 
Private Sub cmdByVal() 
    Dim i as Integer 
    i = 10 
    passByVal i 
    MsgBox i 
End Sub 

在通過引用它沒有說明它是通過引用函數。任何想法?

回答

1
maybe you should do this. 

Private Sub cmdByRef() 
    Dim i as Integer 
    i = 10 
    passByRef i 
    MsgBox "Result of passByRef " + i 
End Sub 
Private Sub cmdByVal() 
    Dim i as Integer 
    i = 10 
    passByVal i 
    MsgBox "Result of passByVal " + i 
End Sub 
+0

感謝傢伙,它的工作原理。 –