![](https://iknow-base.cdn.bcebos.com/lxb/notice.png)
VB自定义函数如何实现将所要返回的数组赋给函数值
PublicFunctionBinary(ByValaAsInteger)AsInteger()DimN1()AsInteger……SetBinary=N1EndFunc...
Public Function Binary(ByVal a As Integer) As Integer()
Dim N1() As Integer
……
Set Binary = N1
End Function
为何会出现不能给数组赋值的错误? 展开
Dim N1() As Integer
……
Set Binary = N1
End Function
为何会出现不能给数组赋值的错误? 展开
2个回答
展开全部
声明一个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
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
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询