2009-07-08 61 views
2

在下面的代码,我得到一个编译时错误:Visual Basic 6.0中通过引用的问题传递

ByRef Argument type mismatch. 

但是,如果我改变我的声明,J到:

Dim i As Integer 
Dim j As Integer 

错误消失了。为什么?

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 

回答

9

这是因为当你这样做的VB6:

Dim i, j As Integer 

它读给编译器作为

Dim i As Variant, j As Integer 

领导到您的类型不匹配。答案是,正如你所说的,对类型同时声明,无论是在你的代码:

Dim i As Integer 
Dim j As Integer 

或者在一行,一拉:

Dim i As Integer, j As Integer 
3

在VB 6,我被认为是一个变体,而不是你描述的情况下的整数。

这是描述行为的article