Visual Basic 6 数组作为参数
这听起来可能是一个愚蠢的问题,但我即将听到。
我有一个 Sub,我想解析一个数组并将其分配给一个类模块“对象”。
我该怎么做呢?
我所做的不起作用的是:
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)
我收到以下错误消息:
类型不匹配:需要数组或用户定义的类型。
This might sound like a stupid question, but I am about to pull hear out.
I have a Sub whereby I want to parse an array and assign it to a Class Module "Object".
How do I go about doing this.
What I do have that isn't working is:
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)
I get the following error message:
Type mismatch: array or user-defined type expected.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这有效:
“类”
因此删除类中矩阵数组的尺寸。如果尺寸必须恰好为 9,您始终可以实施错误检查。
编辑:我在测试时没有考虑就删除了过程调用周围的括号,它可能会影响答案。
This works:
'The Class'
So remove the dimensioning of the matrix array in your class. You can always implement errorchecking if the dimensions must be exactly 9.
EDIT: I removed the parens around the procedure calling without thinking while testing, it may influence the answer.
我认为您需要将数组作为多维数组的变体传递
查看 this文章。
I think you need to pass the array as a variant for multidimensional arrays
Check out this article.
当您调用
customObj.SetMatrixArray()
时,请尝试以下任一操作:删除过程参数周围的括号:
-- 或 --
在调用前加上
Call
:When you call
customObj.SetMatrixArray()
try either:Dropping the parens around the procedure parameter:
-- or --
Prefacing your call with
Call
: