Using TimeScaledData with C# and Project 2003

S

Steve Herndon

This is follow on question that I have regarding TimeScaledData and .NET.
I'd like to move my VB.Net COM-plugin over to C# and am having difficulties
with the TimeScaledData call. I have the VB code working but directly
translating this into C# gets unexpected results (An unexpected error
occured with the method.). The exception type is
System.Runtime.InteropServices.COMException.

The sample data that I'm using is simple
Engineering No 45d 4.5d Mon 1/6/03 Fri 3/7/03
Task 1 No 10d 0d Mon 1/20/03 Fri 1/31/03
Task 1a No 5d 0d Mon 1/20/03 Fri 1/24/03
Task 1 b No 5d 0d Mon 1/27/03 Fri 1/31/03
Task 2 No 10d 10d Mon 1/6/03 Fri 1/17/03
Task 3 No 15d 0d Mon 2/3/03 Fri 2/21/03
Task 4 No 15d 0d Mon 2/17/03 Fri 3/7/03
Task 5 No 20d 0d Mon 1/6/03 Fri 1/31/03
Task 6 No 30d 0d Mon 1/6/03 Fri 2/14/03

The C# code that iterates over the data set, culling for applicable tasks is
listed below. The expected output would be to list the number of minutes
that each task is worked on during the period.

What am I missing that causes the exception?

Thanks,
Steve Herndon
Project Manager
Cranky Pants Games
sherndon -at- crankypg -dot- com

foreach (MSProject.Task task in proj.ActiveProject.Tasks)
{
DateTime dStart = (DateTime)task.Start;
DateTime dFinish = (DateTime)task.Finish;

DateTime dBoundStart = new DateTime(2003, 1, 19);
DateTime dBoundEnd = new DateTime(2003, 1, 26);

if (((DateTime.Compare(dStart, dBoundStart) >= 0) &&
(DateTime.Compare(dStart, dBoundEnd) <= 0)) ||
((DateTime.Compare(dFinish, dBoundStart) >= 0) &&
(DateTime.Compare(dFinish, dBoundEnd) <= 0)) ||
(DateTime.Compare(dStart, dBoundStart) < 0)&&
(DateTime.Compare(dFinish, dBoundEnd) > 0))
{
double accum = 0.0;

Debug.WriteLine(task.Name);

MSProject.TimeScaleValues tsvs = task.TimeScaleData(
dBoundStart,
dBoundEnd,
MSProject.PjTaskTimescaledData.pjTaskTimescaledActualWork,
MSProject.PjTimescaleUnit.pjTimescaleDays,
1);

foreach (MSProject.TimeScaleValue tsv in tsvs)
{
double d = 0.0;

try
{
string s = Convert.ToString(tsv.Value);
d = Convert.ToDouble(s);
}
catch (Exception ex)
{
d = 0.0;
}

accum += d;
}

Debug.WriteLine(Convert.ToString(accum), "Accum");
}
}
 

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