我现在想通过byref将几个参数从函数传出去,试验了这个最简单的小程序。为什么会出错!
Private Sub Form_Load()
Dim a, b, c As Integer
a = 1
b = 8
Call swap(a, b)
Debug.Print "a= " & a, "b= " & b
End Sub
Private Sub swap(ByRef a As Integer, ByRef b As Integer)
Dim temp As Integer
temp = a
a = b
b = temp
End Sub
[解决办法]
Private Sub Form_Load()
Dim a As Integer, b As Integer, c As Integer
a = 1
b = 8
Call swap(a, b)
Debug.Print "a= " & a, "b= " & b
End Sub
Private Sub swap(ByRef a As Integer, ByRef b As Integer)
Dim temp As Integer
temp = a
a = b
b = temp
End Sub
问题出在定义变量上了
VB中定义多个变量不能像楼主那样的
dim a as integer,b as integer,c as double,d as string,e as single