VB自定义函数如何实现将所要返回的数组赋给函数值

来源:百度知道 编辑:UC知道 时间:2024/06/25 11:54:14
Public Function Binary(ByVal a As Integer) As Integer()
Dim N1() As Integer
……
Set Binary = N1
End Function
为何会出现不能给数组赋值的错误?

声明一个private type,用它做返回类型
Private Type AA
N1() As Integer
End Type

Private Function TestFunction() As AA
ReDim TestFunction.N1(3) As Integer
Dim N1(3) As Integer
N1(0) = 0
N1(1) = 1
N1(2) = 2
N1(3) = 3
TestFunction.N1 = N1
End Function

Private Sub Command1_Click()
Dim ArrayRet As AA
ArrayRet = TestFunction
For i = LBound(ArrayRet.N1) To UBound(ArrayRet.N1)
Print ArrayRet.N1(i)
Next
End Sub

VB 函数不能返回数组
只能通过变通方法解决