这听起来可能是个愚蠢的问题,但我要把它拉出来。
我有一个子程序,通过它我想解析一个数组并将它分配给一个类模块"Object“。
我该怎么做呢。
我所拥有的不起作用的是:
Private matrix(9,9) As Integer
'The Setter Sub
Public Sub SetMatrixArray(arrValToSet() as Integer)
matrix = arrValToSet
End Sub
'In the caller module / class module I have the following code to parse the array.
Dim theArray(9,9) As Integer
Dim customObj as CustomObject
customObj.SetMatrixArray(theArray)我收到以下错误消息:
类型不匹配:期望数组或用户定义类型。
发布于 2011-05-18 20:23:14
这样做是可行的:
'In the caller module / class module I have the following code to parse the array.'
Dim theArray(9,9) As Integer
Dim customObj as CustomObject
customObj.SetMatrixArray theArray“全班”
Private matrix() As Integer
'The Setter Sub '
Public Sub SetMatrixArray(arrValToSet() as Integer)
matrix = arrValToSet
End Sub 因此,删除类中矩阵数组的标注。如果尺寸必须为9,则始终可以实现错误检查。
编辑:我删除了程序调用的父母,在测试过程中没有考虑,这可能会影响答案。
发布于 2011-05-18 19:18:16
我认为您需要将数组作为多维数组的变体传递。
Public Sub SetMatrixArray(arrValToSet as Variant)
matrix = arrValToSet
End Sub查看这文章。
发布于 2011-05-18 20:26:19
当您调用customObj.SetMatrixArray()时,请尝试:
删除过程参数周围的父母:
customObj.SetMatrixArray theArray-或者
用Call作为您电话的开头
Call customObj.SetMatrixArray(theArray)https://stackoverflow.com/questions/6049684
复制相似问题