Problem writing data using timescaledata

H

Hilary

I am having a problem writing values into Actual Cost and Actual Work. I am
trying to write data from another application into these values and spread it
across a number of weeks, but once it gets past 9 weeks (item 10 and beyond
in timescaledata) the values are not written into timescaledata, instead when
I debug it, it says "An unexpected error occurred with the method" . I have
tried various methods of writing to the timescaledata but I get the same
thing. The basic code is below (I've taken out bits that aren't important)
Dim TSVs As TimeScaleValues
Dim TSV As TimeScaleValue
Set TSVs = ActiveProject.Tasks(ID).Assignments(AssID).TimeScaleData _
(taskstart, StatusDate, pjAssignmentTimescaledActualCost,
pjTimescaleWeeks)
For Each TSV In TSVs
TSV = CStr(Format(.Fields("Costs To Date") / Weeks,
"0.000"))
Next

Can anyone help me?
 
H

Hilary

No it's not. I actually check if it is a holiday week and input 0 into it if
it is, but this doesn't get written in either.

It doesn't write anything in for any items above item 9, although after this
macro has run and looking in the Task Usage view there are values written in
(sometimes random values)
 
J

Jan De Messemaeker

Hi Hilary,

Just a gusess but how is the setting Actual Costs are always calculated by
Project?
 
R

Rod Gill

If the dates between taskstart and the status date is only 9 weeks, then
there won't be a TSV for week 10. If you still want to add data to it you
need to Add an extra timeslice. See the Add method for TimeScaleData object
 
H

Hilary

Not sure what you mean, but Actual Costs are not calculated by project in
this instance, the actual costs and actual work values are taken from another
application (access database) and then written into this application.
 
H

Hilary

The dates between taskstart and the status date is greater than 9 weeks (in
the example that I have been looking at it was 60 weeks). I'm not sure what
you mean by Add an extra timeslice. I have already tried using the Add
method for TimeScaleData object as below
TSVs.Add CStr(Format(.Fields("Costs To Date") / Weeks, "0.000")), Cnt
Is that what you mean? I still get the same result.
 
R

Rod Gill

Try:
Dim TSVs As TimeScaleValues
Dim TSV As TimeScaleValue
Set TSVs = ActiveProject.Tasks(ID).Assignments(AssID).TimeScaleData _
(taskstart, StatusDate, pjAssignmentTimescaledActualCost,
pjTimescaleWeeks)
For Each TSV In TSVs
TSV.Value = Round(.Fields("Costs To Date") / Weeks,2)
Next
 
J

Jan De Messemaeker

Exactly.
Look in Tools, Options, Calculation whether the option is not set to forbid
you to enter your actual costs.
 
R

Rod Gill

In your project, select the Task Usage view, add the actual cost row then
enter actual costs manually from week 1 of the assignment on to the status
date.

If Project won't allow you to do this manually you have a setting somewhere
that is causing the problem. If you can't do it manually, VBA can't do it
either. If you can do this manually we need to think again!
 
H

Hilary

I can write it in manually.
The macro was originally written to just write the present month's actuals
in (up to 5 weeks) for each task and this has been working for a long time -
so there is no problem writing these values. I have been trying to update
the macro to write the total costs and work for each task and spread it
across the number of weeks, and this usually takes it over the 9 week
barrier. Is there some sort of limitation in the number of TSVs ?
 
H

Hilary

The option "Actual costs are always calculated by Microsoft Project" is not
checked. I get the same results with Actual Work.
As mentioned in my reply to Rod Gill I am updating a macro, that currently
works, that writes the Actual Costs and Actual Work for the current month. I
am updating it to write the total Actual Costs and total Actual Work for each
task which is usually more that the 9 weeks.
I am wondering if there is some limitation in the number of TSVs that it can
handle.
 
R

Rod Gill

No limitation. If you force a date 10 weeks after the start date, does the
code work. Increasingly I am thinking that your dates are setup wrongly.
When the code breaks, please let me know what the start and finish dates are
in the Timescaledata method.
 
H

Hilary

I have changed the code to write the value 10 for each week and I still get
the same result. (I have even tried writing 0 each week with the same result
for items 11 onwards)
The start date in this particular case is 04/01/05 and the finish date is
31/03/06, although I have tried it for numerous tasks with all sorts of dates
(greater that 10 weeks) and still get the same results.

I have just found something on another forum that states that there is an
internal resource limit in Project which prevents holding references to more
than 9 TimeScaleValue objects at the same time, and the .NET garbage
collector is not clearing up the references fast enough.

I goes on to say that s work-around for this is to force the garbage
collector to clean up its references after each execution of the loop, this
is done by placing a call to System.GC.Collect() at the end of the loop.

I have just tried this but I get a debug error - run time error '424':
object required. Am I using it incorrectly?
 
E

Eric Hutzelman

I'm seeing this same issue as well. Getting what seem to be random
ComExceptions when referencing the TimeScaleValue.Value property:

TimeScaleValues timeScaleValues = assignment.TimeScaleData(startDate,
endDate, PjAssignmentTimescaledData.pjAssignmentTimescaledActualWork,
PjTimescaleUnit.pjTimescaleDays, 1);

foreach (TimeScaleValue tsValue in timeScaleValues)
{
// ComException thrown by tsValue.Value at random times
object value = tsValue.Value;
}

I have tried putting in the GC.Collect() before the end of the loop, but I
still get the ComExceptions as before.
 
E

Eric Hutzelman

Got it sorted out, so just an FYI in case anyone else runs into this. It
does indeed seem to be fixed by the GC, but you also need to put in this line
after the GC.Collect() to allow the GC time to do its thing:

GC.WaitForPendingFinalizers();
 

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