Search code examples
vbacompiler-errorsdynamic-arrays

How to pass a dynamic array into a VBA object. Compile error: Invalid use of property


I'm trying to pass an array into a custom class for storage and further use within that object. The class object has the following definition:

' 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

The module that calls this code looks like this:

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

The last line in the above code is giving me the compile error: Invalid use of property.

I believe that the syntax of me Let function is correct, but I might be missing a more subtly nuanced oversight.

Can anyone see what I'm doing wrong? I'm working with Excel 2003 and VBA 6.5 on Windows XP.

Any suggestions would be greatly appreciated.

Thanks,

Christos


Solution

  • a property is not a method call and you need to set it equal to your array:

    objResult.InterpDates = int_dates
    

    There still might be an issue with the array your passing in but this is a first step.