繁体   English   中英

Visual Basic 6数组作为参数

[英]Visual Basic 6 Array as Argument

这可能听起来像一个愚蠢的问题,但我即将拉出来。

我有一个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)

我收到以下错误消息:

类型不匹配:预期的数组或用户定义类型。

这有效:

 '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,则始终可以实施错误检查。

编辑:我在测试过程中不假思索地移除了程序周围的parens,它可能会影响答案。

我认为你需要将数组作为多维数组的变体传递

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

看看这篇文章。

当你调用customObj.SetMatrixArray()尝试:

删除过程参数周围的parens:

customObj.SetMatrixArray theArray

- 要么 -

通过Call接听您的Call

Call customObj.SetMatrixArray(theArray)

暂无
暂无

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

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