Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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".

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.

like image 833
Koekiebox Avatar asked Dec 16 '22 13:12

Koekiebox


1 Answers

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.

like image 83
Dabblernl Avatar answered Jan 11 '23 21:01

Dabblernl