Timescale Values

J

Jon Stoackley

Hi,

I'm having a problem accessing the timescale values for tasks within a
project.

I can create a timescalevalues collection for the resource assignment to the
task and I can read most of them by saying "For each TimescaleValue in
TimescaleValues". This works most of the time - however some tasks seem to
have a timescalevalue that although it has a valid date, throws an exception
when you attempt to read it. Specifically it's the get_Value method that
fails with an unspecified exception message.

I've tried checking for timescale values that are nothing, but that doesn't
seem to filter it.

I've also tried the IsNumeric function and using a try - catch statement to
discard any values that can not be resolved to numbers.

Can anyone out there shed any light on this?

Thanks,

Jon.
 
J

John

Jon Stoackley said:
Hi,

I'm having a problem accessing the timescale values for tasks within a
project.

I can create a timescalevalues collection for the resource assignment to the
task and I can read most of them by saying "For each TimescaleValue in
TimescaleValues". This works most of the time - however some tasks seem to
have a timescalevalue that although it has a valid date, throws an exception
when you attempt to read it. Specifically it's the get_Value method that
fails with an unspecified exception message.

I've tried checking for timescale values that are nothing, but that doesn't
seem to filter it.

I've also tried the IsNumeric function and using a try - catch statement to
discard any values that can not be resolved to numbers.

Can anyone out there shed any light on this?

Thanks,

Jon.

Jan,
A few years ago when I was first attempting to read values with the
TimescaleData Method, I ran into a similar problem. I was reading Work
values and converting the default minutes to hours by dividing by 60.
The formula didn't like dividing a null value by anything so I put in a
simple "If" statement to test for null and jump around it if present.
Although I've never used it, the "IsNull" statement might also work.

You mention something about a "get_Value" method. What is that? I'm not
aware of any such method in VBA. Perhaps a snippet of your code would
help.

John
Project MVP
 
R

Rod Gill

For time periods with no value (EG a split or before or after a task start
and finish, the value property for some reason returns "". So, to get a 0
use:

val(timescalevalue.value) val("") returns 0 (zero)
 
J

Jon Stoackley

Thanks for the help - I've tried the Val thing and also using the IsDBNull
(replacing IsNull in VB.Net) function. Still have problems. The error message
I get is:

"System.Runtime.InteropServices.COMException (0x800A03EC): An unexpected
error occurred within the method.

At MSProject.TimescaleValue.get_Value()"

I guess the get_Value function is part of the property pair for the Value
method of the timescale value object?

The code I am using is:

Try

'Attempt to get a list of the timescale
values for the task

TaskTimescaleValues =
TestTask.TimeScaleData(Today, TestTask.Finish,
MSProject.PjTaskTimescaledData.pjTaskTimescaledWork,
MSProject.PjTimescaleUnit.pjTimescaleDays)

Catch ex As Exception

'Error handling
MsgBox(ex.ToString)

End Try

'Go through each element of timescale data
For Each TestTimescaleValue In TaskTimescaleValues

'Attempt to add the value to the total
forecast
Try

'Test for the value being null
If Not
(IsDBNull(TestTimescaleValue.Value)) Then

'Test whether the returned value is
greater than zero
If Val(TestTimescaleValue.Value) > 0
Then

'Try summing the value
ReturnForecast += CSng(Val
TestTimescaleValue.Value))

End If

End If

Catch ex As Exception

'Error handling?
MsgBox(ex.ToString)

End Try


You may need to put it into a text editor to see it in it's entirety!

It's like it just doesn't want to give me the value. I've tried testing for
Nothing and Null and string representations. The error thrown is the same,
although it happens at different values, depending on where the task is moved
to.

I'm effectively trying to get a forecast to complete - ie in time terms, how
much work is there left to complete from today onwards.

Many thanks again for all your help.

Jon.
 
J

John

Jon Stoackley said:
Thanks for the help - I've tried the Val thing and also using the IsDBNull
(replacing IsNull in VB.Net) function. Still have problems. The error message
I get is:

"System.Runtime.InteropServices.COMException (0x800A03EC): An unexpected
error occurred within the method.

At MSProject.TimescaleValue.get_Value()"

I guess the get_Value function is part of the property pair for the Value
method of the timescale value object?

The code I am using is:

Try

'Attempt to get a list of the timescale
values for the task

TaskTimescaleValues =
TestTask.TimeScaleData(Today, TestTask.Finish,
MSProject.PjTaskTimescaledData.pjTaskTimescaledWork,
MSProject.PjTimescaleUnit.pjTimescaleDays)

Catch ex As Exception

'Error handling
MsgBox(ex.ToString)

End Try

'Go through each element of timescale data
For Each TestTimescaleValue In TaskTimescaleValues

'Attempt to add the value to the total
forecast
Try

'Test for the value being null
If Not
(IsDBNull(TestTimescaleValue.Value)) Then

'Test whether the returned value is
greater than zero
If Val(TestTimescaleValue.Value) > 0
Then

'Try summing the value
ReturnForecast += CSng(Val
TestTimescaleValue.Value))

End If

End If

Catch ex As Exception

'Error handling?
MsgBox(ex.ToString)

End Try


You may need to put it into a text editor to see it in it's entirety!

It's like it just doesn't want to give me the value. I've tried testing for
Nothing and Null and string representations. The error thrown is the same,
although it happens at different values, depending on where the task is moved
to.

I'm effectively trying to get a forecast to complete - ie in time terms, how
much work is there left to complete from today onwards.

Many thanks again for all your help.

Jon.


Jan,
Since you're working with VB.net I'll leave this one to Rod. I have only
worked with VBA and the methods I suggested solved the problem.

John
Project MVP
 
J

Jon Stoackley

John,

Thanks for your reply - in the last few hours I've tried duplicating the
code in a macro within MSP, and it all works fine.

This doesn't really help me to determine what the problem is with the
managed AddIn that I'm writing!

I guess it's back to the drawng board....

Thanks,

Jon.
 
J

Jon Stoackley

Rod,

I'm saying:

Dim TaskTimescaleValues as MSProject.TimescaleValues
Dim TestTimescaleValue as MSProject.TimescaleValue

The MSProject namespace is coming from the Project 11.0 COM library reference.

Thanks,

Jon.
 
L

Lars Hammarberg

You'll have to check for the date actually being a working date - if it is,
you can get the value using '.value' otherwise you'll throw an exception.

If ActiveProject.Calendar.Period(myDate, myDate).Working = true then...
 
J

Jon Stoackley

Lars,

Tried testing for working days, but it doesn't seem to help. Exactly the
same errors are generated.

Something else which has come to light is that the first time it's run,
there are no errors reported, then subsequent runs of the code generate
errors.

I have seen data being written back into the tasks - unintelligable data. It
has shown up before in Task Usage view but I haven't been able to duplicate
it since.

It's directly related to collecting the timesheet values and then attempting
to read through them.

I am guessing that by reading the data, I am somehow writing rubbish data
back into the timephased data collection, which is causing the property get
of the Value method to fail on the subsequent runs.

There is something more complicated going on here. I need to try to wrap my
head around it.

Thanks for your help,

Jon.
 
L

Lars Hammarberg

Could be related to debugging... try simply compiling your code and run it!
 

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