【发布时间】:2010-02-03 05:31:38
【问题描述】:
我认为我对如何通过 Property Get 和 Let 在 VBA 中处理模块级数组有很好的了解。有没有办法通过属性重新调整模块级数组?
以下代码在最后一个过程 (DoTest) 中的 ReDim 语句处出错。
Private mstrTestArray() As String
Private Sub Class_Initialize()
ReDim mstrTestArray(0) As String
End Sub
Private Property Get TestArray() As String()
TestArray = mstrTestArray
End Property
Private Property Let TestArray(ByRef strTestArray() As String)
mstrTestArray = strTestArray
End Property
Private Property Get TestArrayValue(d1 As Long) As String
TestArrayValue = mstrTestArray(d1)
End Property
Private Property Let TestArrayValue(d1 As Long, strValue As String)
mstrTestArray(d1) = strValue
End Property
Sub DoTest()
Dim intCharCode As Integer
For intCharCode = 97 To 122
If Not Len(TestArrayValue(UBound(TestArray))) > 0 Then
TestArrayValue(UBound(TestArray)) = Chr(intCharCode)
Else
ReDim Preserve TestArray(UBound(TestArray) + 1) As String
TestArrayValue(UBound(TestArray)) = Chr(intCharCode)
End If
Next intCharCode
Debug.Print TestArrayValue(LBound(TestArray)) _
& " through " _
& TestArrayValue(UBound(TestArray))
End Sub
谢谢!
【问题讨论】: