Reputation: 497
So I have two different classes, the main and the object class. The thing is that I want to send two arrays to setArray
but Property Let
doesn't allow me too. How can I do this, I know that dData.setArray = xData(0), xData(1)
is wrong but that's how I would do it if I have one argument.
Main:
dData.setArray = xData(0), xData(1)
Object Class:
Property Let setArray(name As Variant, value As Variant)
Dim i As Long
For i = 0 To UBound(name)
data.Add CStr(name(i)), CInt(value(i))
Next i
End Property
Upvotes: 4
Views: 1327
Reputation: 43585
If you are willing to pass the arrays as one jagged array, you may achieve this with the following code:
Public Sub TestMe()
Dim myObject As New someObject
Dim arr1 As Variant: arr1 = Array(1, 2, 3, 4, 5)
Dim arr2 As Variant: arr2 = Array("a", "b")
myObject.Members = Array(arr1, arr2)
Dim arrCnt As Long
Dim counter As Long
'This is how to access the values in the jagged array:
For arrCnt = LBound(myObject.Members) To UBound(myObject.Members)
For counter = LBound(myObject.Members(arrCnt)) To UBound(myObject.Members(arrCnt))
Debug.Print myObject.Members(arrCnt)(counter)
Next counter
Next arrCnt
End Sub
The class looks like this:
Private m_Members As Variant
Public Property Get Members() As Variant
Members = m_Members
End Property
Public Property Let Members(ByVal NewValue As Variant)
m_Members = NewValue
End Property
Upvotes: 0
Reputation: 451
You can have property lets with multiple arguments, but obviously with only one 'right hand side', which is the last argument in the property signature (value As Variant
in your case). The assignment syntax for your signature will be this:
dData.setArray(xData(0)) = xData(1)
Upvotes: 6