MS Project COM Exception

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
 
R

Rod Gill

Hi,

If the resources workload finishes before your finish date, the value (at
least in VBA returns "" not 0 because it doesn't exist. A zero would suggest
simply no work for that period. The "" signifies the resource has finished,
or hasn't started in this project yet.

--
Rod Gill
Project MVP
For Microsoft Project companion projects, best practices and Project VBA
development services
visit www.projectlearning.com/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top