Array of Visual Basic 6 as an argument

This may seem like a silly question, but I'm going to break free.

I have a Sub in which I want to parse an array and assign it to a module of the "Object" class.

How can i do this.

I have something that does not work:

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) 

The following error message appears:

Type mismatch: an array or user type is expected.

+4
source share
3 answers

It 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 

'Class'

 Private matrix() As Integer 'The Setter Sub ' Public Sub SetMatrixArray(arrValToSet() as Integer) matrix = arrValToSet End Sub 

So, remove the dimension of the matrix array in your class. You can always perform error checking if the dimensions must be exactly 9.

EDIT: I removed the parens around the call procedure without thinking during testing, this may affect the answer.

+6
source

I think you need to pass an array as an option for multidimensional arrays

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

Check out this article.

+3
source

When you call customObj.SetMatrixArray() , try either:

Removing pairs around a procedure parameter:

 customObj.SetMatrixArray theArray 

- or -

Preprocessing your call with Call :

 Call customObj.SetMatrixArray(theArray) 
+3
source

All Articles