【发布时间】:2018-10-27 20:56:08
【问题描述】:
我有一个名为 cSchedule 的类对象,它包含一个成员 pTimeline,它是一个 cDay 对象数组。我正在尝试使用 pTimeline 的 Get 属性在特定索引处返回 cDay 对象,但出现以下错误“运行时错误'438':对象不支持此属性或方法” .
我从我的主模块调用这个函数,如下所示
Dim TestDay As cDay
Set TestDay = TestSchedule.Timeline(1)
我已验证 TestSchedule 包含所有正确的数据,所以问题在于我如何尝试在 pTimeline 的特定索引处获取对 cDay 对象的引用。
' Class Module: cSchedule
Private pTimeline() As cDay
Private pFitness As Double
Private pMap As Collection
'Number of units the timeline is divided into. E.g if weeks, pNumTimeUnits should be 52*numYears
Private pNumTimeUnits As Integer
''''''''''''''''''''''
' Timeline property
''''''''''''''''''''''
Public Property Get Timeline(Optional argIndex As Variant) As Variant
If IsMissing(argIndex) Then
Timeline = pTimeline
Else
Dim selectedDay As Variant
selectedDay = pTimeline(argIndex).Copy
Set Timeline = selectedDay
End If
End Property
Public Property Let Timeline(Optional argIndex As Variant, arrValue As Variant)
Dim arrLength As Integer
Dim intIndex As Integer
' Resize array if incoming list of activities is greater than current
arrLength = (UBound(arrValue) - LBound(arrValue) + 1)
If arrLength <> pNumTimeUnits Then
ReDim Preserve pTimeline(arrLength)
pNumTimeUnits = arrLength
End If
pTimeline = arrValue
End Property
谁能提供洞察我做错了什么以及从包含对象数组的类成员中获取对象的正确方法是什么?
【问题讨论】:
-
Set TestDay = TestSchedule.Timeline.Item(1) 能改进吗??
-
您应该包含
cDay类。您几乎还应该尽可能地明确键入变量。 -
@Gary'sStudent 我相信 .Item 仅用于集合,而我使用的是数组,所以我认为这不会有帮助