我仍然很难解决这个问题。我正在使用自定义类模块:TimeFrame 和 TimeSheet。以下是缩短版本:
_________________________
'TIMEFRAME CLASS MODULE
'This class records Military Time, but allows
'you to also display it in Civilian Time
Private pHours As Integer
Private pMinutes As Integer
Private pTotalMinutes As Integer
Public Property Get hours() As Integer
hours = pHours
End Property
Public Property Let hours(Value As Integer)
If Value >= 1 And Value <= 24 Then
pHours = Value
Else
Err.Raise 9009, , "Hours Value [" & CStr(Value) & "] is not valid."
End If
End Property
Public Property Get minutes() As Integer
minutes = pMinutes
End Property
Public Property Let minutes(Value As Integer)
If Value >= 0 And Value <= 59 Then
pMinutes = Value
Else
Err.Raise 9010, , "Minutes Value [" & CStr(Value) & "] is not valid."
End If
End Property
Public Property Let Initialize(str As String)
'This property expects a string formatted like: 08:30
Dim vhours As String
Dim vminutes As String
Dim arrTime() As String
If InStr(str, Me.Delimiter) Then
arrTime = Split(str, Me.Delimiter)
vhours = Trim(arrTime(0))
vminutes = Trim(arrTime(1))
If IsNumeric(vhours) Then
pHours = CInt(vhours)
End If
If IsNumeric(vminutes) Then
pMinutes = CInt(vminutes)
End If
Else
'Set to defaults
pHours = 0
pMinutes = 0
End If
End Property
...
_____________________________
'TIMESHEET CLASS MODULE
Private pEmployeeID As Integer
Private pStartDate As Date
Private pEndDate As Date
Private pMonStart As TimeFrame
Private pMonEnd As TimeFrame
Private pMonBreak As Double
Private pTuesStart As TimeFrame
Private pTuesEnd As TimeFrame
Private pTuesBreak As Double
Private pWedStart As TimeFrame
Private pWedEnd As TimeFrame
Private pWedBreak As Double
Private pThursStart As TimeFrame
Private pThursEnd As TimeFrame
Private pThursBreak As Double
Private pFriStart As TimeFrame
Private pFriEnd As TimeFrame
Private pFriBreak As Double
Public Property Get EmployeeID() As Integer
EmployeeID = pEmployeeID
End Property
Public Property Let EmployeeID(Value As Integer)
If Value > 0 Then
pEmployeeID = Value
Else
MsgBox "Employee ID " & Value & " is an incorrect value." & vbCrLf & "Employee ID must be a positive integer"
End If
End Property
Public Property Get StartDate() As Date
StartDate = pStartDate
End Property
Public Property Let StartDate(Value As Date)
pStartDate = Value
End Property
Public Property Get EndDate() As Date
EndDate = pEndDate
End Property
Public Property Let EndDate(Value As Date)
pEndDate = Value
End Property
Public Property Get MondayStart() As TimeFrame
Set MondayStart = pMonStart
End Property
Public Property Set MondayStart(ByRef Value As TimeFrame)
Set pMonStart = Value
End Property
Public Property Get MondayEnd() As TimeFrame
Set MondayEnd = pMonStart
End Property
Public Property Set MondayEnd(ByRef Value As TimeFrame)
Set pMonEnd = Value
End Property
Public Property Get MondayBreak() As Double
MondayBreak = pMonBreak
End Property
Public Property Let MondayBreak(Value As Double)
pMonBreak = Value
End Property
Public Property Get TuesdayStart() As TimeFrame
Set TuesdayStart = pTuesStart
End Property
Public Property Set TuesdayStart(ByRef Value As TimeFrame)
Set pTuesStart = Value
End Property
Public Property Get TuesdayEnd() As TimeFrame
Set TuesdayEnd = pTuesStart
End Property
Public Property Set TuesdayEnd(ByRef Value As TimeFrame)
Set pTuesEnd = Value
End Property
Public Property Get TuesdayBreak() As Double
TuesdayBreak = pTuesBreak
End Property
Public Property Let TuesdayBreak(Value As Double)
pTuesBreak = Value
End Property
...
在我的主模块中,我一个接一个地调用两个子例程。
- 我有一个名为 TimeSheetCollection 的全局变量,它是一个包含 TimeSheet 类型实例的集合
- 首先,我调用子例程 ReadWeeklyTimeSheets(),它设置 TimeSheetCollection 对象,读取今天的邮件项,并根据从邮件项正文中获得的值设置每个 TimeSheet 中的属性。这个子程序工作得很好。
- 接下来,调用名为 ExportTimeSheetsToDatabase() 的子例程。我输入了几个 Debug.print 语句,在 Item.MondayStart 和 Item.MondayEnd 属性上收到错误消息:“对象不支持此属性或方法”
主要模块:
Sub ExportTimeSheetsToDatabase()
Dim Item As TimeSheet
For Each Item In TimeSheetCollection
Debug.Print "TSCollection Count: " & TimeSheetCollection.count
Debug.Print Item.EmployeeID & ", " & Item.StartDate & ", " & Item.EndDate
Debug.Print Item.MondayStart '<<< Error occurs here
Debug.Print Item.MondayEnd
Debug.Print "Toal Hours: " & Item.TotalWeeklyHours
Next Item
End Sub
由于 Item 是 TimeSheet 类型,您可以从上面的 Class Module 中看到它确实包含 Get 方法:
Public Property Get MondayStart() As TimeFrame
Set MondayStart = pMonStart
End Property
根据我的研究,语法似乎是正确的,当我键入点运算符“。”时 在 Item 我的列表出现后,显示所有属性。这不像我拼错了什么。请指教。
艾伦