在VBA中通过引用传递不起作用

时间:2011-06-27 17:56:10

标签: ms-access access-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 个答案:

答案 0 :(得分: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