Arrays 设置并获取固定大小的数组

Arrays 设置并获取固定大小的数组,arrays,vba,excel,Arrays,Vba,Excel,例如,我有一个类,它有一个固定大小的数组Double Private m_values(8) as Double 数组的Let和Get方法的正确语法是什么 Public Property Let Values (RHS(8) as Double) m_values = RHS End Property Public Property Get Values() as Double Values = m_values End Property 我不清楚语法的具体部分: a。在L

例如,我有一个类,它有一个固定大小的数组
Double

Private m_values(8) as Double
数组的
Let
Get
方法的正确语法是什么

Public Property Let Values (RHS(8) as Double)
    m_values = RHS
End Property

Public Property Get Values() as Double
    Values = m_values
End Property
我不清楚语法的具体部分:

a。在
Let
方法中,
RHS(8)作为Double
是传递8个数组
Double
的正确方法吗?
B我可以简单地使用赋值将一个数组复制到另一个数组吗?(例如,
m_值=值


C对于
Get
方法,将
函数声明为Double
是正确的,还是应该像
那样声明为Double(8)

尝试遵守以下规则:

'starting point- array with 8 elements
Dim arrStart(8) As Double
    arrStart(8) = 1     'here- for testing with Local window

'passing array to another...Variant type variable
    'no array declaration required
Dim arrVariant As Variant
    arrVariant = arrStart

'passing array to another Double variable
    'dynamic array declaration required
Dim arrEmpty() As Double
    arrEmpty = arrStart

当将变量(作为参数)传递给另一个属性、函数或子例程时,这些规则也起作用。这也意味着您不能将Get属性声明为数组,而应将其声明为变量类型。

声明可容纳数组的属性的唯一方法是as
Variant
Property

Private m_values As Variant

Public Property Let Values(RHS As Variant)
    m_values = RHS
End Property

Public Property Get Values() As Variant
    Values = m_values
End Property

Public Sub Test()
    Dim x(8) As Double
    x(1) = 123.55
    x(2) = 456.45
    x(5) = 789.66
    x(8) = 123.777

    ' assign value to property
    Values = x

    ' get value from property
    Dim y() As Double
    y = Values

    Dim i As Integer
    For i = 0 To UBound(y)
        Debug.Print y(i)
    Next

End Sub