变量类型的VBA数组类属性 [英] VBA Array of variant type as class property

查看:158
本文介绍了变量类型的VBA数组类属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有几个处理数字阵列(double类型)一类,也需要处理描述符的数组,其中包括字符串和整数,这就需要被用作相应的字符串和数字的组合。所以,我决定做Variant类型数组属性(不包含数组的Variant)。但是这一次似乎没有工作,而double类型的数组做。

具体而言,这种类型的双数组属性做工精细,一次全部接收或返回一个数组:

 私人p_dbNumericArray()为双公共属性让NumericArray(价值()为双)
    p_dbNumericArray()=()值
高端物业
公共属性获取NumericArray()为双()
    NumericArray()= p_dbNumericArray()
高端物业

但是,当我尝试用变异类型的​​数组相同的模式,获取属性返回一个空的/未分配的变量数组:

 私人p_vaVariantArray()为Variant公共属性让VariantArray(价值()为Variant)
    p_vaVariantArray()=()值
高端物业
公共属性获取VariantArray()为Variant()
    VariantArray()= p_vaVariantArray()
高端物业

在一个变体结束语一个数组(而不是让Variant类型的数组),当然正常工作:

 私人p_vaVariantArray为Variant公共属性让VariantArray(价值为Variant)
    p_vaVariantArray =值
高端物业
公共属性获取VariantArray()为Variant
    VariantArray = p_vaVariantArray
高端物业

但它是已知的标准,对于昏暗D()的作品为双模式不适合昏暗V()为Variant工作,属性?


解决方案

 公共财产获取VariantArray()为Variant()
    VariantArray = p_vaVariantArray()
高端物业

请注意缺少的括号内。

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?

解决方案

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

Note the missing parentheses.

这篇关于变量类型的VBA数组类属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆