VBA array of variant type as a class property

I have a class that processes several numeric arrays (double type), and must also handle an array of descriptors, which will include a combination of strings and integers, which should be used as strings and numbers, respectively. So I decided to create an array property of a variant type (not a variant containing an array). But this one doesn't seem to work, while the types of double arrays.

In particular, this double array-property type works great to get or return an array right away:

Private p_dbNumericArray() As Double

Public Property Let NumericArray(Value() As Double)
    p_dbNumericArray() = Value()
End Property
Public Property Get NumericArray() As Double()
    NumericArray() = p_dbNumericArray()
End Property

But when I try to use the same template with an array of type options, the Get property returns an empty / unallocated array of options:

Private p_vaVariantArray() As Variant

Public Property Let VariantArray(Value() As Variant)
    p_vaVariantArray() = Value()
End Property
Public Property Get VariantArray() As Variant()
    VariantArray() = p_vaVariantArray()
End Property

An array wrapper in a variant (instead of an array of a variant of a type), of course, works fine:

Private p_vaVariantArray As Variant

Public Property Let VariantArray(Value As Variant)
    p_vaVariantArray = Value
End Property
Public Property Get VariantArray() As Variant
    VariantArray = p_vaVariantArray
End Property

, , Dim D() Double Dim V() As Variant, ?

+3
1
Public Property Get VariantArray() As Variant()
    VariantArray = p_vaVariantArray()
End Property

.

+2

All Articles