我在查找程序的正确结构时遇到问题,我正在尝试使用类来解决它,但没有成功。
我为患者提供1个班级,每个患者都有以下内容:
然后每个外科医生应该有一个每天的时间表。
因此,我正在考虑使用另一个课程来安排每日课程,其中应该有:
我的想法中的某些东西看起来并不正确,我很难理解我应该做些什么。
1)我的结构是否符合我想做的事情?
2)我如何检查外科医生是否有计划的每日安排,以及他是否未将患者添加到他的日程安排中?
非常感谢任何帮助。
谢谢, 乔治
Private mstrName As String
Private mstrOperationDescription As String
Private mlngSurgeon As Long
Private mdblOpDuration As Double
Public Property Get Name() As String
Name = mstrName
End Property
Public Property Get OperationDescription() As String
OperationDescription = mstrOperationDescription
End Property
Public Property Get Surgeon() As Long
Surgeon = mlngSurgeon
End Property
Public Property Get OpDuration() As Double
OpDuration = mdblOpDuration
End Property
Private mlngDay As Long
Private mdblTotalDuration As Double
Public Property Get Day() As Long
Day = mlngDay
End Property
Public Property Let Day(ByVal lDay As Long)
mlngDay = lDay
End Property
Public Property Get TotalDuration() As Double
TotalDuration = mdblTotalDuration
End Property
Public Property Let TotalDuration(ByVal dTotalDuration As Double)
mdblTotalDuration = dTotalDuration
End Property
Public Sub Test()
Dim mydata As New clsData
Dim schedule1 As New clsSchedule
Dim schedule2 As New clsSchedule
Dim i As Integer
mydata.InputData
For i = 1 To mydata.PatientCount
If mydata.patient(i).Surgeon = 1 Then
schedule1.TotalDuration = schedule1.TotalDuration + mydata.patient(i).OpDuration
Else
schedule2.TotalDuration = schedule2.TotalDuration + mydata.patient(i).OpDuration
End If
Next i
MsgBox "Total Duration is: " & schedule1.TotalDuration
End Sub
答案 0 :(得分:0)
一种解决方案是拥有一组外科医生对象和一组患者对象。每位患者都有一名外科医生作为财产,每位外科医生都有一组患者。
由此您可以了解所有属于外科医生的患者的总手术时间。
诀窍是知道对象如何相互关联 - 在这种情况下,每个患者都有一个外科医生,每个外科医生可以有很多患者。这在逻辑上导致了以下结构:
Private mstrName As String
Private mstrOperationDescription As String
Private mobjSurgeon As cSurgeon
Private mdblOpDuration As Double
Property Let Name(txt As String)
mstrName = txt
End Property
Property Let OperationDescription(txt As String)
mstrOperationDescription = txt
End Property
Property Let Surgeon(objSurgeon As cSurgeon)
Set mobjSurgeon = objSurgeon
End Property
Property Let OpDuration(num As Double)
mdblOpDuration = num
End Property
Property Get OpDuration() As Double
OpDuration = mdblOpDuration
End Property
Private mstrName As String
Private mlngSurgeonId As Long
Private mcolPatients As Collection
Private Sub Class_Initialize()
Set mcolPatients = New Collection
End Sub
Property Let Name(txt As String)
mstrName = txt
End Property
Property Get Name() As String
Name = mstrName
End Property
Property Let IdNumber(num As Long)
mlngSurgeonId = num
End Property
Property Get IdNumber() As Long
IdNumber = mlngSurgeonId
End Property
Sub AddPatient(objPatient As cPatient)
mcolPatients.Add objPatient, objPatient.Name
End Sub
Function TotalHours() As Double
Dim objPatient As cPatient
For Each objPatient In mcolPatients
TotalHours = TotalHours + objPatient.OpDuration
Next objPatient
End Function
Sub CheckSurgeonHours()
Dim colSurgeons As Collection
Set colSurgeons = New Collection
Dim colPatients As Collection
Set colPatients = New Collection
'Populate Surgeon and Patient collections from input data
'This is the static data for each object, i.e. name, Id, operation type/duration
Dim objSurgeon As cSurgeon
For Each objSurgeon In colSurgeons
Dim objPatient As cPatient
For Each objPatient In colPatients
objPatient.Surgeon = objSurgeon
objSurgeon.AddPatient objPatient
Next objPatient
Debug.Print objSurgeon.TotalHours
Next objSurgeon
End Sub