gpt4 book ai didi

vba - 如何将动态数组传递给 VBA 对象。编译错误: Invalid use of property

转载 作者:行者123 更新时间:2023-12-02 10:42:17 25 4
gpt4 key购买 nike

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

' 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。

任何建议将不胜感激。

谢谢,

克里斯托斯

最佳答案

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

objResult.InterpDates = int_dates

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

关于vba - 如何将动态数组传递给 VBA 对象。编译错误: Invalid use of property,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13802262/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com