Visual Basic 6 数组作为参数

发布于 2024-11-07 18:24:25 字数 510 浏览 0 评论 0原文

这听起来可能是一个愚蠢的问题,但我即将听到。

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

べ繥欢鉨o。 2024-11-14 18:24:25

这有效:

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

编辑:我在测试时没有考虑就删除了过程调用周围的括号,它可能会影响答案。

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.

EDIT: I removed the parens around the procedure calling without thinking while testing, it may influence the answer.

メ斷腸人バ 2024-11-14 18:24:25

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

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

查看 this文章。

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.

Saygoodbye 2024-11-14 18:24:25

当您调用 customObj.SetMatrixArray() 时,请尝试以下任一操作:

删除过程参数周围的括号:

customObj.SetMatrixArray theArray

-- 或 --

在调用前加上 Call

Call customObj.SetMatrixArray(theArray)

When you call customObj.SetMatrixArray() try either:

Dropping the parens around the procedure parameter:

customObj.SetMatrixArray theArray

-- or --

Prefacing your call with Call:

Call customObj.SetMatrixArray(theArray)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文