如何将动态数组传递到VBA对象。编译错误:属性的使用无效
我试图将一个数组传递到一个自定义类中,以便存储并在该对象中进一步使用。类对象具有以下定义:如何将动态数组传递到VBA对象。编译错误:属性的使用无效,vba,compiler-errors,dynamic-arrays,Vba,Compiler Errors,Dynamic Arrays,我试图将一个数组传递到一个自定义类中,以便存储并在该对象中进一步使用。类对象具有以下定义: ' 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(
' 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
上面代码的最后一行给出了编译错误:属性的使用无效
我相信me Let函数的语法是正确的,但我可能遗漏了一个更微妙的疏忽
有人能看出我做错了什么吗?我正在Windows XP上使用Excel 2003和VBA 6.5
如有任何建议,将不胜感激
谢谢
Christos属性不是方法调用,您需要将其设置为与数组相等:
objResult.InterpDates = int_dates
您传入的数组可能仍然存在问题,但这是第一步。完全正确。我来自Java和MAtlab的背景,对“getter”和“setter”还有其他一些先入为主的概念。谢谢你,菲利普。