![](/img/trans.png)
[英]Setting an array value results in an Argument not optional error in Visual Basic
[英]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.