类模块中的redim属性

use*_*138 2 vba properties

我很擅长在vba中使用类.我试图使用数组作为一个属性,其中数组的长度必须是可变的.我正在寻找一种方法来做到这一点,但我真的不明白这些属性是如何工作的.

所以我在类模块中定义我的数组

Private pTestArray() As String
Run Code Online (Sandbox Code Playgroud)

以及获取和设置值的属性

Private Property Get TestArrayValue(index As Long) As String
    TestArrayValue = qTestArray(index)
End Property

Private Property Let ArrayValue(index As Long, strValue As String)
    pTestArray(index) = strValue
End Property
Run Code Online (Sandbox Code Playgroud)

但是我找不到一种方法来重新调整阵列.任何线索?谢谢C.

Ale*_* K. 5

所以你想调整大小?然后你可以检查和处理Let属性中的边界;

Private Property Let ArrayValue(index As Long, strValue As String)
    If index > UBound(pTestArray) Then ReDim Preserve pTestArray(index)
    pTestArray(index) = strValue
End Property
Run Code Online (Sandbox Code Playgroud)

您还需要redim pTestArray(0)Class_Initialize事件中初始维度.