开发者

VBA Array of variant type as class property

开发者 https://www.devze.com 2023-02-18 14:54 出处:网络
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 string

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 emp开发者_JS百科ty/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?


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

Note the missing parentheses.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号