通过类属性分配整个专用阵列

时间:2017-11-07 17:55:17

标签: vba excel-vba class properties excel

我有一个固定大小的数组作为我的一个类的私有变量。有没有办法设置一个get / let属性,允许我将整个数组传递给对象,还是我必须独立分配值?公共职能怎么样?

1 个答案:

答案 0 :(得分:1)

我不确定,但也许你在谈论这样的事情。 名为cArray的类

NA

并进行测试

Option Explicit

Dim mArr(1 To 5) As String

Property Get aValue() as Variant
    aValue = mArr
End Property

Private Sub Class_Initialize()
    mArr(1) = "Test1"
    mArr(2) = "Test2"
    mArr(3) = "Test3"
    mArr(4) = "Test4"
    mArr(5) = "Test5"
End Sub`

更新:对于let部分,您需要一个循环

Option Explicit

Sub Test()
Dim c As cArray
Dim v As Variant
Dim i As Long

    Set c = New cArray
    v = c.aValue
    For i = LBound(v) To UBound(v)
        Debug.Print v(i)
    Next i

End Sub