我有多个资源(学习者,辅导员和房间)分配给任务(培训课程),我想确定哪些是双重预订,然后将它们添加到文本列。
我正在使用TimeScale方法,我目前正在尝试计算双重预订,假设任何资源的时间超过在该会话的给定开始和结束日期分配给它们的会话长度必须是双重预订。
但是,我无法确定如何确定分配的总时间。 pjTimeScale属性似乎没有返回我需要的东西。使用pjTimescaleHours最接近应返回的实际值。
我错过了什么?还是有更好的方法?
Sub Overallocations()
'T.Text19 is the Overallocation column
'Identify the overallocations and the source ID
Dim T As Task
Dim R As Resource
Dim tsvs As TimeScaleValues
Dim asn As Assignment
For Each T In ActiveProject.Tasks
T.Text19 = ""
Next T
'Start the allocation of Rooms process
For Each T In ActiveProject.Tasks
i = 0
Application.StatusBar = "Checking Session No." & T.ID
'Checks to see if the task is a valid Module session and if it has been
confirmed. Skips if not a session or if its a confirmed session
If Left(T.Name, 1) <> "M" Then
GoTo SkipT
End If
For Each R In T.Resources
Set tsvs = R.TimeScaleData(T.Start, T.Finish, pjResourceTimescaledWork,
pjTimescaleHours)
Duration = (T.Finish - T.Start) * 60 * 24
If tsvs(1).Value > Duration + 1 Then 'THIS IS WHAT IS NOT WORKING
If T.Text19 = "" Then
T.Text19 = R.Name
Else
T.Text19 = T.Text19 & ", " & R.Name
End If
End If
Next R
SkipT:
Next T 'Next Task
MsgBox "The identification of overallocation has been completed.",
vbInformation, "Resource Overallocation Complete"
End Sub
我有多个资源(学习者,辅导员和房间)分配给任务(培训课程),我想确定哪些是双重预订......
换句话说,需要识别分配给重叠训练课程的学习者,辅导员和房间。
虽然这可以使用TimeScaleData
方法完成,但更容易的方法是查找重叠会话。培训课程重叠有四种情况:
所有四种情景都可以用一个共同的表达式来识别:Class B starts before Class A ends and Class B ends after Class A starts
;见下图。
以下是适用于此方法的代码:
Sub IdentifyOverlappingAssignments()
Dim T As Task
Dim R As Resource
For Each T In ActiveProject.Tasks
Application.StatusBar = "Checking Session No." & T.ID
T.Text19 = vbNullString
'Checks to see if the task is a valid Module session and if it has been confirmed.
If Left(T.Name, 1) = "M" Then
For Each R In T.Resources
' check to see if this resource is assigned to another task
' at all during the duration of this task
Dim asn As Assignment
For Each asn In R.Assignments
If asn.Task.UniqueID <> T.UniqueID Then
' do the tasks overlap?
If asn.Task.Finish > T.Start And asn.Task.Start < T.Finish Then
If T.Text19 = "" Then
T.Text19 = R.Name & " (" & asn.Task.ID & ")"
Else
T.Text19 = T.Text19 & ", " & R.Name & " (" & asn.Task.ID & ")"
End If
End If
End If
Next asn
Next R
End If
Next T
MsgBox "The identification of overallocation has been completed." _
, vbInformation, "Resource Overallocation Complete"
End Sub
注意:在这种情况下使用TimeScaleData存在问题,原因有多种,包括:1)资源可以按50%的使用率分配,并且不会被识别为双重预订,因为不会被分配,2)如果课程在半小时开始(例如,上午10:30 - 下午12:00),您需要将时间刻度值缩小到分钟,因为使用pjTimescaleHours将返回整个小时(例如,时间刻度值将从上午10:00开始),这很容易将错误介绍给您的代码。
两件事,一个关于代码的指针和一个问题。
码:
Sub Foo()
Dim T As Task
Dim R As Resource
For Each T In ActiveProject.Tasks
If Not (T Is Nothing) Then
'Task stuff
For Each R In T.Resources
If Not (R Is Nothing) Then
Resource Stuff
End If
Next R
End If
Next T
End Sub