J
Joe Cletcher
Does anyone know what is causing the unexpected error. I receive an error
1004 (An unexpected error occurred with the method) when using the
"TimeScaleData" method to obtain the value entered in the task contour pane.
It occurs at the following line of code.
MyValue =
myProj.Tasks.UniqueID(MyTaskUniqueID).Assignments.UniqueID(MyTaskAssignmentUniqueID).TimeScaleData(BeginDate, _
EndDate,
PjAssignmentTimescaledData.pjAssignmentTimescaledWork, _
PjTimescaleUnit.pjTimescaleYears, 1).Item(1).Value
Some values are returned correctly, the begin date starts at 1/1/2005 and
ends at 1/1/2027 and the end date is 1 year later than the start date. All
values with begin dates greater than 2014 experience the error. The error
message appears randomly for dates between 2005 and 20015 for both
assignments (1st assignment is work in hours and the 2nd assignment is
material cost in $).
While not brief -- I have included a copy of the programming below.
===================================================
Public Sub TestCode()
Dim aYear As Integer
Dim BeginDate As Date
Dim DtStr As String
Dim EndDate As Date
Dim i As Integer
Dim j As Integer
Dim k As Integer
Dim myErrorMsg As String
Dim myMsg As String
Dim myProj As MSProject.Project
Dim MyTask As MSProject.Task
Dim MyTaskAssignment As MSProject.Assignment
Dim MyTaskAssignmentUniqueID As Long
Dim MyTaskName As String
Dim MyTaskResource As MSProject.Resource
Dim MyTaskResourceName As String
Dim MyTaskResourceNmbr As Long
Dim MyTaskRow As Long
Dim MyTaskUniqueID As Long
Dim MyTaskWBS As String
Dim MyValue As String
Dim MyWbsLevel As Long
Dim OLChildren As Long
Dim OLLevel As Long
Dim OLNmbr As String
On Error GoTo ErrorHandler
myProj = GetObject(ProgCon.MSProjectFileNASAInfo.FullName)
SetupTrackBar(myProj.Tasks.Count)
DtStr = "1/1/"
i = 1
For Each MyTask In myProj.Tasks
If MyTask.OutlineChildren.Count = 0 Then
OLChildren = MyTask.OutlineChildren.Count
OLLevel = MyTask.OutlineLevel
OLNmbr = MyTask.OutlineNumber
MyTaskName = MyTask.Name
MyTaskWBS = MyTask.WBS
MyTaskRow = MyTask.ID
MyTaskResourceNmbr = MyTask.Resources.Count
MyWbsLevel = WbsLevel(MyTask.WBS)
MyTaskUniqueID = MyTask.UniqueID
'MyTaskUniqueID = myProj.Tasks(i).UniqueID
myMsg = " Count of Outline Children = " & CStr(OLChildren) &
ControlChars.Cr & _
" Outline Level = " & CStr(OLLevel) &
ControlChars.Cr & _
" Outline Number = " & OLNmbr &
ControlChars.Cr & _
" Task Name = " & MyTaskName &
ControlChars.Cr & _
" Task WBS = " & MyTaskWBS & " level "
& MyWbsLevel & ControlChars.Cr & _
" Task Unique ID = " &
MyTaskUniqueID.ToString & ControlChars.Cr
myMsg = myMsg & " Number of Resources for Task = " &
CStr(MyTaskResourceNmbr) & ControlChars.Cr
myMsg = myMsg & " Project Task ID = " &
myProj.Tasks(i).ID.ToString & ControlChars.Cr
j = 1
For Each MyTaskAssignment In MyTask.Assignments
MyTaskAssignmentUniqueID = MyTaskAssignment.UniqueID
'MyTaskAssignmentUniqueID =
myProj.Tasks.UniqueID(MyTaskUniqueID).Assignments(j).UniqueID
myMsg = myMsg & " Unique ID = " &
MyTaskAssignmentUniqueID.ToString & ControlChars.Cr
'myProj.Application.SelectTimescaleRange(6, "1/1/05", 1,
1)
BeginDate = #1/1/2005#
aYear = 2005
myMsg = myMsg & " FTE/COST Values = "
For k = 1 To 10 'ProgCon.NumberOfCostColumns + 1
EndDate = DtStr & CStr(aYear + 1)
MyTaskResourceName =
Trim(MyTaskAssignment.ResourceName)
MyValue =
myProj.Tasks.UniqueID(MyTaskUniqueID).Assignments.UniqueID(MyTaskAssignmentUniqueID).TimeScaleData(BeginDate, _
EndDate,
PjAssignmentTimescaledData.pjAssignmentTimescaledWork, _
PjTimescaleUnit.pjTimescaleYears, 1).Item(1).Value
'MyTaskResourceName =
Trim(myProj.Tasks.UniqueID(MyTaskUniqueID).Assignments.UniqueID(MyTaskAssignmentUniqueID).ResourceName)
'MyValue =
MyTask.MyTaskAssignment.UniqueID(MyTaskAssignmentUniqueID).TimeScaleData(BeginDate, _
' EndDate,
PjAssignmentTimescaledData.pjAssignmentTimescaledWork, _
' PjTimescaleUnit.pjTimescaleYears,
1).Item(1).Value
If MyTaskResourceName = "KAPL" Then
MyValue = MyValue / 60 / 2080
End If
myMsg = myMsg & MyValue.ToString & ", "
aYear = aYear + 1
BeginDate = EndDate
Next k
myMsg = Left(myMsg, myMsg.Length - 1) & ControlChars.Cr
j = j + 1
Next
If MyTask.Assignments.Count > 0 Then
MyMsgBox(myMsg)
End If
End If
frmMain.TrackBar1.Value = frmMain.TrackBar1.Value + 1
frmMain.Refresh()
frmMain.TrackBar1.Refresh()
i = i + 1
Next MyTask
UnSetTrackBar()
myProj.Application.Quit()
myProj = Nothing
Exit Sub
ErrorHandler:
MyValue = -999
myErrorMsg = Err.Number.ToString & "--" & Err.Description &
ControlChars.Cr
myErrorMsg = myErrorMsg & Err.Source & ControlChars.Cr
myErrorMsg = myErrorMsg & Err.HelpFile & ControlChars.Cr
myErrorMsg = myErrorMsg & ControlChars.Cr & " WBS = " & MyTaskWBS &
ControlChars.Cr
myErrorMsg = myErrorMsg & " Resource Name = " & MyTaskResourceName &
ControlChars.Cr _
& " Begin Date = " & BeginDate.ToShortDateString &
ControlChars.Cr _
& " End Date = " & EndDate.ToShortDateString & ControlChars.Cr
MyMsgBox(myErrorMsg)
Resume Next
End Sub
1004 (An unexpected error occurred with the method) when using the
"TimeScaleData" method to obtain the value entered in the task contour pane.
It occurs at the following line of code.
MyValue =
myProj.Tasks.UniqueID(MyTaskUniqueID).Assignments.UniqueID(MyTaskAssignmentUniqueID).TimeScaleData(BeginDate, _
EndDate,
PjAssignmentTimescaledData.pjAssignmentTimescaledWork, _
PjTimescaleUnit.pjTimescaleYears, 1).Item(1).Value
Some values are returned correctly, the begin date starts at 1/1/2005 and
ends at 1/1/2027 and the end date is 1 year later than the start date. All
values with begin dates greater than 2014 experience the error. The error
message appears randomly for dates between 2005 and 20015 for both
assignments (1st assignment is work in hours and the 2nd assignment is
material cost in $).
While not brief -- I have included a copy of the programming below.
===================================================
Public Sub TestCode()
Dim aYear As Integer
Dim BeginDate As Date
Dim DtStr As String
Dim EndDate As Date
Dim i As Integer
Dim j As Integer
Dim k As Integer
Dim myErrorMsg As String
Dim myMsg As String
Dim myProj As MSProject.Project
Dim MyTask As MSProject.Task
Dim MyTaskAssignment As MSProject.Assignment
Dim MyTaskAssignmentUniqueID As Long
Dim MyTaskName As String
Dim MyTaskResource As MSProject.Resource
Dim MyTaskResourceName As String
Dim MyTaskResourceNmbr As Long
Dim MyTaskRow As Long
Dim MyTaskUniqueID As Long
Dim MyTaskWBS As String
Dim MyValue As String
Dim MyWbsLevel As Long
Dim OLChildren As Long
Dim OLLevel As Long
Dim OLNmbr As String
On Error GoTo ErrorHandler
myProj = GetObject(ProgCon.MSProjectFileNASAInfo.FullName)
SetupTrackBar(myProj.Tasks.Count)
DtStr = "1/1/"
i = 1
For Each MyTask In myProj.Tasks
If MyTask.OutlineChildren.Count = 0 Then
OLChildren = MyTask.OutlineChildren.Count
OLLevel = MyTask.OutlineLevel
OLNmbr = MyTask.OutlineNumber
MyTaskName = MyTask.Name
MyTaskWBS = MyTask.WBS
MyTaskRow = MyTask.ID
MyTaskResourceNmbr = MyTask.Resources.Count
MyWbsLevel = WbsLevel(MyTask.WBS)
MyTaskUniqueID = MyTask.UniqueID
'MyTaskUniqueID = myProj.Tasks(i).UniqueID
myMsg = " Count of Outline Children = " & CStr(OLChildren) &
ControlChars.Cr & _
" Outline Level = " & CStr(OLLevel) &
ControlChars.Cr & _
" Outline Number = " & OLNmbr &
ControlChars.Cr & _
" Task Name = " & MyTaskName &
ControlChars.Cr & _
" Task WBS = " & MyTaskWBS & " level "
& MyWbsLevel & ControlChars.Cr & _
" Task Unique ID = " &
MyTaskUniqueID.ToString & ControlChars.Cr
myMsg = myMsg & " Number of Resources for Task = " &
CStr(MyTaskResourceNmbr) & ControlChars.Cr
myMsg = myMsg & " Project Task ID = " &
myProj.Tasks(i).ID.ToString & ControlChars.Cr
j = 1
For Each MyTaskAssignment In MyTask.Assignments
MyTaskAssignmentUniqueID = MyTaskAssignment.UniqueID
'MyTaskAssignmentUniqueID =
myProj.Tasks.UniqueID(MyTaskUniqueID).Assignments(j).UniqueID
myMsg = myMsg & " Unique ID = " &
MyTaskAssignmentUniqueID.ToString & ControlChars.Cr
'myProj.Application.SelectTimescaleRange(6, "1/1/05", 1,
1)
BeginDate = #1/1/2005#
aYear = 2005
myMsg = myMsg & " FTE/COST Values = "
For k = 1 To 10 'ProgCon.NumberOfCostColumns + 1
EndDate = DtStr & CStr(aYear + 1)
MyTaskResourceName =
Trim(MyTaskAssignment.ResourceName)
MyValue =
myProj.Tasks.UniqueID(MyTaskUniqueID).Assignments.UniqueID(MyTaskAssignmentUniqueID).TimeScaleData(BeginDate, _
EndDate,
PjAssignmentTimescaledData.pjAssignmentTimescaledWork, _
PjTimescaleUnit.pjTimescaleYears, 1).Item(1).Value
'MyTaskResourceName =
Trim(myProj.Tasks.UniqueID(MyTaskUniqueID).Assignments.UniqueID(MyTaskAssignmentUniqueID).ResourceName)
'MyValue =
MyTask.MyTaskAssignment.UniqueID(MyTaskAssignmentUniqueID).TimeScaleData(BeginDate, _
' EndDate,
PjAssignmentTimescaledData.pjAssignmentTimescaledWork, _
' PjTimescaleUnit.pjTimescaleYears,
1).Item(1).Value
If MyTaskResourceName = "KAPL" Then
MyValue = MyValue / 60 / 2080
End If
myMsg = myMsg & MyValue.ToString & ", "
aYear = aYear + 1
BeginDate = EndDate
Next k
myMsg = Left(myMsg, myMsg.Length - 1) & ControlChars.Cr
j = j + 1
Next
If MyTask.Assignments.Count > 0 Then
MyMsgBox(myMsg)
End If
End If
frmMain.TrackBar1.Value = frmMain.TrackBar1.Value + 1
frmMain.Refresh()
frmMain.TrackBar1.Refresh()
i = i + 1
Next MyTask
UnSetTrackBar()
myProj.Application.Quit()
myProj = Nothing
Exit Sub
ErrorHandler:
MyValue = -999
myErrorMsg = Err.Number.ToString & "--" & Err.Description &
ControlChars.Cr
myErrorMsg = myErrorMsg & Err.Source & ControlChars.Cr
myErrorMsg = myErrorMsg & Err.HelpFile & ControlChars.Cr
myErrorMsg = myErrorMsg & ControlChars.Cr & " WBS = " & MyTaskWBS &
ControlChars.Cr
myErrorMsg = myErrorMsg & " Resource Name = " & MyTaskResourceName &
ControlChars.Cr _
& " Begin Date = " & BeginDate.ToShortDateString &
ControlChars.Cr _
& " End Date = " & EndDate.ToShortDateString & ControlChars.Cr
MyMsgBox(myErrorMsg)
Resume Next
End Sub