J
Jonathan Fong
Hi,
I have some trouble with MS Project COM object. The following C# code
segment has given me an "An unexpected error occurred with the method"
exception during accessing timeScaleValue.Value after 10 looping in the
foreach. However, there is not problem accessing other properties such as
timeScaleValue.StartDate and timeScaleValue.EndDate in the loop
individually. It seems the MS Project COM object having problem to return
the result of the value property from 11th item in the timeScaleValues
collection.
Resources resources = this._oMSApp.ActiveProject.Resources;
foreach(Resource resource in resources)
{
MSProject.TimeScaleValues timeScaleValues =
resource.TimeScaleData("1/12/1999", "1/12/2003",
MSProject.PjResourceTimescaledData.pjResourceTimescaledCost,
MSProject.PjTimescaleUnit.pjTimescaleDays, 1);
foreach(TimeScaleValue timeScaleValue in timeScaleValues)
{
object val = timeScaleValue.Value; // Exception here
string str = val.ToString();
}
}
I also tested a similar code segment in the VBA. It is working fine if I did
not do any watch mode. Moreover, it had given the same exception result in
the Watches of the debug mode.
Private Sub CommandButton1_Click()
Dim TSV As TimeScaleValues, HowMany As Long
Dim HoursPerDay As String
Set TSV = ActiveCell.Resource.TimeScaleData("1/11/99", "10/11/00",
TimescaleUnit:=pjTimescaleDays)
For HowMany = 1 To TSV.Count
HoursPerDay = HoursPerDay & TSV(HowMany).Value
Next HowMany
MsgBox HoursPerDay
End Sub
Does anyone have faced the similar problem or can someone explain to me what
is the cause of the"An unexpected error occurred with the method"
exception?
Regards
Jonathan
I have some trouble with MS Project COM object. The following C# code
segment has given me an "An unexpected error occurred with the method"
exception during accessing timeScaleValue.Value after 10 looping in the
foreach. However, there is not problem accessing other properties such as
timeScaleValue.StartDate and timeScaleValue.EndDate in the loop
individually. It seems the MS Project COM object having problem to return
the result of the value property from 11th item in the timeScaleValues
collection.
Resources resources = this._oMSApp.ActiveProject.Resources;
foreach(Resource resource in resources)
{
MSProject.TimeScaleValues timeScaleValues =
resource.TimeScaleData("1/12/1999", "1/12/2003",
MSProject.PjResourceTimescaledData.pjResourceTimescaledCost,
MSProject.PjTimescaleUnit.pjTimescaleDays, 1);
foreach(TimeScaleValue timeScaleValue in timeScaleValues)
{
object val = timeScaleValue.Value; // Exception here
string str = val.ToString();
}
}
I also tested a similar code segment in the VBA. It is working fine if I did
not do any watch mode. Moreover, it had given the same exception result in
the Watches of the debug mode.
Private Sub CommandButton1_Click()
Dim TSV As TimeScaleValues, HowMany As Long
Dim HoursPerDay As String
Set TSV = ActiveCell.Resource.TimeScaleData("1/11/99", "10/11/00",
TimescaleUnit:=pjTimescaleDays)
For HowMany = 1 To TSV.Count
HoursPerDay = HoursPerDay & TSV(HowMany).Value
Next HowMany
MsgBox HoursPerDay
End Sub
Does anyone have faced the similar problem or can someone explain to me what
is the cause of the"An unexpected error occurred with the method"
exception?
Regards
Jonathan