简体   繁体   English

Visual Basic 6数组作为参数

[英]Visual Basic 6 Array as Argument

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". 我有一个Sub,我想解析一个数组并将其分配给类模块“对象”。

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. 类型不匹配:预期的数组或用户定义类型。

This works: 这有效:

 '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

'The Class' '班级'

Private matrix() As Integer 
       'The Setter Sub '
       Public Sub SetMatrixArray(arrValToSet() as Integer)
       matrix = arrValToSet
    End Sub 

So remove the dimensioning of the matrix array in your class. 因此,删除类中矩阵数组的尺寸。 You can always implement errorchecking if the dimensions must be exactly 9. 如果维度必须精确为9,则始终可以实施错误检查。

EDIT: I removed the parens around the procedure calling without thinking while testing, it may influence the answer. 编辑:我在测试过程中不假思索地移除了程序周围的parens,它可能会影响答案。

I think you need to pass the array as a variant for multidimensional arrays 我认为你需要将数组作为多维数组的变体传递

Public Sub SetMatrixArray(arrValToSet as Variant)
    matrix = arrValToSet
End Sub

Check out this article. 看看这篇文章。

When you call customObj.SetMatrixArray() try either: 当你调用customObj.SetMatrixArray()尝试:

Dropping the parens around the procedure parameter: 删除过程参数周围的parens:

customObj.SetMatrixArray theArray

-- or -- - 要么 -

Prefacing your call with Call : 通过Call接听您的Call

Call customObj.SetMatrixArray(theArray)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM