在下面的代碼中,我得到編譯時錯誤,因爲i
被視爲變體。錯誤是:「ByRef參數類型不匹配」。Visual Basic 6.0通過值傳遞參考差異
但是,如果我通過參數ByVal
,爲什麼沒有錯誤?
Private Sub Command2_Click()
Dim i, j As Integer
i = 5
j = 7
Call Swap(i, j)
End Sub
Public Sub Swap(ByRef X As Integer, ByRef Y As Integer)
Dim tmp As Integer
tmp = X
X = Y
Y = tmp
End Sub