3

I have a class that handles several numeric arrays (type double) and also needs to handle an array of descriptors, which will include a mix of strings and integers, which need to be utilized as strings and numbers accordingly. So I decide to make an array property of type variant (not a variant containing an array). But this one does not seem to work, while the type double arrays do.

Specifically, this type double array-property works fine, to receive or return an array all at once:

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 the same pattern with an array of type variant, the Get property returns an empty/unallocated variant array:

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

Wrapping an array in a variant (instead of having an array of type variant), 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

But is it known and standard that the pattern that works for Dim D() As Double does not work for Dim V() As Variant, in properties?

1 Answer 1

2
Public Property Get VariantArray() As Variant()
    VariantArray = p_vaVariantArray()
End Property

Note the missing parentheses.

Sign up to request clarification or add additional context in comments.

3 Comments

Gah--another easy one! Thanks. What about the analogous line for the Double array " NumericArray( ) = p_dbNumericArray( ) ", which seems to work fine with the extra parens? Are they optional here? Or is something subtle going on? Thanks again.
Whoops. Looks like that "NumericArray( ) = ..." actually doesn't work. I lost track of editing too many things at the same time. So those parentheses are just absolutely wrong. Thanks again.
@Romnie: Yes, the parens are always absolutely wrong. They are calling the function, but you actually want to assign to it (i.e. set the return value).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.