所以我有两个不同的类,主要类和对象类。问题是我想向setArray
发送两个数组,但是Property Let
也不允许我。我该怎么做,我知道dData.setArray = xData(0), xData(1)
是错误的,但是如果我有一个参数,那就是我会这样做的方式。
主要:
dData.setArray = xData(0), xData(1)
对象类:
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
答案 0 :(得分:3)
您可以拥有带有多个参数的属性let,但显然只有一个“右侧”,这是属性签名中的最后一个参数(在您的情况下为value As Variant
)。您的签名的分配语法为:
dData.setArray(xData(0)) = xData(1)
答案 1 :(得分:0)
如果您愿意将数组作为一个锯齿状的数组传递,则可以使用以下代码来实现:
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
该类如下:
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