使用变量而不是字段名
Using a variable instead of the fieldname
我在 Microsoft 项目中有 4 个自定义字段。 "Optimistic"、"MostLikely" 和 "Pessimistic" 是任何 3 个 Duration 字段的必需自定义名称。 "CriticalCnt" 也是 20 个数字字段中任何一个的必填自定义名称。我有一个例程,它标识已自定义的 Microsoft Project Fieldname,我已将其分配给一个变量。
当我为每个任务寻找这些字段的值时,我想使用变量来标识字段。
我已经为 "ProjectSummaryTask","FieldConstantToFieldname",FieldnametoFieldConstant"
研究了网络,但没有成功。
我想做的是:
Dim i as integer, fieldvalue as long, Tsk as Task
For I = 1 to ActiveProject.task.count do
Fieldvalue =Activeproject.Task.CriticalCnt
Debug.print ("Task=" & Task(i).id & " Task(i).CriticalCnt=" &
Task(i).CriticalCnt)
next i
此例程获取用于标识 CustomNamed 字段的 9 位代码。在这种情况下,Number4 被分配了 "CriticalCnt" 的 CustomName。我不知道此例程中使用值 3 更新了什么。
Sub GetFieldID()
Dim Projectfield As Long, ProjectFieldName As String, Message As String, i
As Integer, tasks As tasks, t As Long, NT As Long, tmp As tasks, criticalCnt
As String
Projectfield = FieldNameToFieldConstant("CriticalCnt", pjDuration)
Message = "ProjectfieldNumber = " & Projectfield & vbCrLf
MsgBox Message & ActiveProject.ProjectSummaryTask.GetField(Projectfield)
ActiveProject.ProjectSummaryTask.SetField FieldID:=Projectfield, Value:="3"
ProjectFieldName = FieldConstantToFieldName(Projectfield)
Message = "New Value for Field:" & ProjectFieldName & vbCrLf
MsgBox Message & ActiveProject.ProjectSummaryTask.GetField(Projectfield)
Set tasks = ActiveProject.tasks
NT = tasks.Count
Debug.Print ("NT=" & NT)
For t = 1 To NT
Debug.Print ("T=" & t)
Debug.Print (".id = " & tasks(t).ID & " Value= " & Projectfield & _
" tasks(t).Projectfield= " & Projectfield)
Debug.Print ("Value=" & _
ActiveProject.ProjectSummaryTask.GetField(Projectfield))
Next t
End Sub
此函数查找使用名称 "CriticalCnt" 自定义的数字字段,并使用它来识别三个自定义持续时间字段中的哪一个包含每个任务的正确持续时间,并输出每个任务的 ID 及其自定义持续时间。请注意,CriticalCnt 包含自定义持续时间字段(九位数字)的 字段 ID。
Sub GetCustomDuration()
' Schedule contains 4 customized fields--1 number field and 3 duration fields.
' The duration fields are named "Optimistic", "MostLikely" and "Pessimistic".
' Each task uses one of these fields and the selected one is identified in the
' customized number field called "CriticalCnt" which contains its field ID.
' find the field customized to contain the CriticalCnt data
Dim fldCriticalCnt As Long
fldCriticalCnt = Application.FieldNameToFieldConstant("CriticalCnt")
Dim tsk As Task
For Each tsk In ActiveProject.Tasks
' determine which of the three duration fields to use for this task
Dim fldCustomDur As Long
fldCustomDur = CLng(tsk.GetField(fldCriticalCnt))
' get the custom duration value
Dim CustomDur As String
CustomDur = tsk.GetField(fldCustomDur)
Debug.Print "Task=" & tsk.ID & " CriticalCnt=" & CustomDur _
& " (" & DurationValue(CustomDur) & " minutes)"
Next tsk
End Sub
注意:对于最终用户而言,存储自定义持续时间字段的 name 似乎比字段 ID 更好。在这种情况下,CriticalCnt 将是一个自定义的文本字段,其中包含三个项目的下拉列表:"Optimistic"、"MostLikely" 和 "Pessimistic".
我在 Microsoft 项目中有 4 个自定义字段。 "Optimistic"、"MostLikely" 和 "Pessimistic" 是任何 3 个 Duration 字段的必需自定义名称。 "CriticalCnt" 也是 20 个数字字段中任何一个的必填自定义名称。我有一个例程,它标识已自定义的 Microsoft Project Fieldname,我已将其分配给一个变量。 当我为每个任务寻找这些字段的值时,我想使用变量来标识字段。
我已经为 "ProjectSummaryTask","FieldConstantToFieldname",FieldnametoFieldConstant"
研究了网络,但没有成功。
我想做的是:
Dim i as integer, fieldvalue as long, Tsk as Task
For I = 1 to ActiveProject.task.count do
Fieldvalue =Activeproject.Task.CriticalCnt
Debug.print ("Task=" & Task(i).id & " Task(i).CriticalCnt=" &
Task(i).CriticalCnt)
next i
此例程获取用于标识 CustomNamed 字段的 9 位代码。在这种情况下,Number4 被分配了 "CriticalCnt" 的 CustomName。我不知道此例程中使用值 3 更新了什么。
Sub GetFieldID()
Dim Projectfield As Long, ProjectFieldName As String, Message As String, i
As Integer, tasks As tasks, t As Long, NT As Long, tmp As tasks, criticalCnt
As String
Projectfield = FieldNameToFieldConstant("CriticalCnt", pjDuration)
Message = "ProjectfieldNumber = " & Projectfield & vbCrLf
MsgBox Message & ActiveProject.ProjectSummaryTask.GetField(Projectfield)
ActiveProject.ProjectSummaryTask.SetField FieldID:=Projectfield, Value:="3"
ProjectFieldName = FieldConstantToFieldName(Projectfield)
Message = "New Value for Field:" & ProjectFieldName & vbCrLf
MsgBox Message & ActiveProject.ProjectSummaryTask.GetField(Projectfield)
Set tasks = ActiveProject.tasks
NT = tasks.Count
Debug.Print ("NT=" & NT)
For t = 1 To NT
Debug.Print ("T=" & t)
Debug.Print (".id = " & tasks(t).ID & " Value= " & Projectfield & _
" tasks(t).Projectfield= " & Projectfield)
Debug.Print ("Value=" & _
ActiveProject.ProjectSummaryTask.GetField(Projectfield))
Next t
End Sub
此函数查找使用名称 "CriticalCnt" 自定义的数字字段,并使用它来识别三个自定义持续时间字段中的哪一个包含每个任务的正确持续时间,并输出每个任务的 ID 及其自定义持续时间。请注意,CriticalCnt 包含自定义持续时间字段(九位数字)的 字段 ID。
Sub GetCustomDuration()
' Schedule contains 4 customized fields--1 number field and 3 duration fields.
' The duration fields are named "Optimistic", "MostLikely" and "Pessimistic".
' Each task uses one of these fields and the selected one is identified in the
' customized number field called "CriticalCnt" which contains its field ID.
' find the field customized to contain the CriticalCnt data
Dim fldCriticalCnt As Long
fldCriticalCnt = Application.FieldNameToFieldConstant("CriticalCnt")
Dim tsk As Task
For Each tsk In ActiveProject.Tasks
' determine which of the three duration fields to use for this task
Dim fldCustomDur As Long
fldCustomDur = CLng(tsk.GetField(fldCriticalCnt))
' get the custom duration value
Dim CustomDur As String
CustomDur = tsk.GetField(fldCustomDur)
Debug.Print "Task=" & tsk.ID & " CriticalCnt=" & CustomDur _
& " (" & DurationValue(CustomDur) & " minutes)"
Next tsk
End Sub
注意:对于最终用户而言,存储自定义持续时间字段的 name 似乎比字段 ID 更好。在这种情况下,CriticalCnt 将是一个自定义的文本字段,其中包含三个项目的下拉列表:"Optimistic"、"MostLikely" 和 "Pessimistic".