Reputation: 5963
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.
Upvotes: 4
Views: 5509
Reputation: 16101
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.
Upvotes: 6
Reputation: 53593
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)
Upvotes: 3
Reputation: 6554
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.
Upvotes: 3