2

我正在尝试将数组传递给自定义类以进行存储并在该对象中进一步使用。类对象具有以下定义:

' Class Name: MBRMCurves
Implements ICurves

Private m_lInterpDates() As Long

Public Property Get InterpDates() As Long()

    InterpDates = m_lInterpDates

End Property

Public Property Let InterpDates(lInterpDates() As Long)

    m_lInterpDates = lInterpDates

End Property

调用此代码的模块如下所示:

Dim objResult     As New MBRMCurves

    'Store the forward prices
    Dim fx_fwd()      As Double

    'Store the interpolation dates
    Dim int_dates()   As Long

    'initially there are no people
    Dim NumberTenors  As Integer
    NumberTenors = 0

    Dim cell          As range

    ' Create ranges of Dates
    Dim range     As range
    Dim range_topcell As range

    ' TODO Pri1 Create the Curves Obj
    With Worksheets("test")

        ' Populate the dates of the FWD rates.
        Set range_topcell = .range("B5")
Debug.Print range_topcell.Value
        Set range = .range(range_topcell, range_topcell.End(xlDown))
Debug.Print range.Count

        ' Add more columns to the FWD array
        ReDim fx_fwd(0 To range.Count - 1, 0 To 3)
        ReDim int_dates(0 To range.Count - 1)

        ' Set the counter
        NumberTenors = 0

        ' Populate the dates of the FWD rates into the first column of the dates array.
        For Each cell In range
            NumberTenors = NumberTenors + 1
            int_dates(NumberTenors - 1) = cell.Value
        Next cell

        ' Add interpolation dates to Curves object
        objResult.InterpDates int_dates

上面代码的最后一行给了我编译错误:Invalid use of property。

我相信我 Let 函数的语法是正确的,但我可能会错过一个更微妙的疏忽。

谁能看到我做错了什么?我在 Windows XP 上使用 Excel 2003 和 VBA 6.5。

任何建议将不胜感激。

谢谢,

克里斯托斯

4

1 回答 1

2

属性不是方法调用,您需要将其设置为等于您的数组:

objResult.InterpDates = int_dates

您传入的数组可能仍然存在问题,但这是第一步。

于 2012-12-10T14:26:53.440 回答