The trick to this tip is to remember that a variant can hold any type of data, including an array. Just define the property as a variant and use it as an array.
The following code is in a class called CArray
Private m_MyArray As Variant
Public Property Get MyArray() As Variant
MyArray = m_MyArray
End Property
Public Property Let MyArray(a As Variant)
m_MyArray = a
End Property
You can then use these properties in several different ways, as illustrated by the following code from a form
Private m_Array As CArray
Private mArr(3) As String
Private Sub Form_Load()
Set m_Array = New CArray
mArr(1) = "One"
mArr(2) = "Two"
mArr(3) = "Three"
m_Array.MyArray = mArr()
'OR
'm_Array.MyArray = Array("One", "Two", "Three")
End Sub
Private Sub Form_Unload(Cancel As Integer)
Dim i As Integer
For i = 1 To UBound(m_Array.MyArray)
MsgBox m_Array.MyArray(i)
Next
End Sub
|