Vb6 Visual Basic 6.0通过引用传递问题

Vb6 Visual Basic 6.0通过引用传递问题,vb6,pass-by-reference,Vb6,Pass By Reference,在以下代码中,我得到一个编译时错误: ByRef Argument type mismatch. 但如果我将I,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, ByR

在以下代码中,我得到一个编译时错误:

ByRef Argument type mismatch. 
但如果我将I,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

这是因为在VB6中执行此操作时:

Dim i, j As Integer
它读取到编译器作为

Dim i As Variant, j As Integer
导致您的类型不匹配。答案是,正如您所说,用类型声明这两种类型,或者在代码中声明:

Dim i As Integer
Dim j As Integer
或者在一条线上,一个la:

Dim i As Integer, j As Integer

在VB6中,我被认为是一个变量,而不是您描述的情况下的整数

下面是一个描述行为的示例