Undefined date field value "NA"

B

Binoy

Hi,

Can someone kindly let me know how I can retrieve the text that Microsoft
Project uses for empty date fields using VBA, which works across different
regional settings? For e.g. for a US English installation, the undefined date
value is displayed as "NA".

Is there any property of the activeProject object that I could use for this
purpose? Currently, we use activeProject.Tasks(1).getField(pjTaskStart1) at
the time of initialization of project, but this results in different results
on different machines (NA on most, system date on a few)

Thanks,
Binoy
 
J

Jim Aksel [MVP]

I do not know of a universal value or property that you can access. What I
do is try to compare it to something else.
For example, a completed task will have [Finish]=[Actual Finish]. A task
that is not yet finished will have [Actual Finish]="NA" or what ever "NA" is
for the given language pack.

So, if I want to test if a task is complete, I don't test for [Actual
Finish]="NA" ... Instead I test if [Finish]=[Actual Finish]. For certain
the value of [Finsih] can never equal NA.

However, that gets a little trickier for things like baselines... how do I
know if I have a baseline date? One other thing I found was when testing
for "NA", I recognized that "NA" was either smaller than the smallest
possible date, or larger than the largest possible date so I tested on that.
However, I found in VBA and VB.NET the logic seems to reverse.

Hope that helped. Post back if you can't work around it.

Jim Aksel, MVP
 
B

Binoy

Hi Jim,

Thank you for replying.

The suggested workaround however will not work in my case. What I have is a
function which takes a variant (dates) as an argument and then converts it
into a specific date format (which is then returned as a string).

Before I parse the date, I need to verify two conditions on the input
argument,
1) it is not empty
2) it is defined (i.e. not "NA")

I need some way to accomplish (2) which works across all regional
settings/locales. What I am thinking is that I could take this value from
some unused date field in Microsoft Project for comparison.

Please advise.

Thanks in Advance & Merry Xmas,
Binoy

Jim Aksel said:
I do not know of a universal value or property that you can access. What I
do is try to compare it to something else.
For example, a completed task will have [Finish]=[Actual Finish]. A task
that is not yet finished will have [Actual Finish]="NA" or what ever "NA" is
for the given language pack.

So, if I want to test if a task is complete, I don't test for [Actual
Finish]="NA" ... Instead I test if [Finish]=[Actual Finish]. For certain
the value of [Finsih] can never equal NA.

However, that gets a little trickier for things like baselines... how do I
know if I have a baseline date? One other thing I found was when testing
for "NA", I recognized that "NA" was either smaller than the smallest
possible date, or larger than the largest possible date so I tested on that.
However, I found in VBA and VB.NET the logic seems to reverse.

Hope that helped. Post back if you can't work around it.

Jim Aksel, MVP

Binoy said:
Hi,

Can someone kindly let me know how I can retrieve the text that Microsoft
Project uses for empty date fields using VBA, which works across different
regional settings? For e.g. for a US English installation, the undefined
date
value is displayed as "NA".

Is there any property of the activeProject object that I could use for
this
purpose? Currently, we use activeProject.Tasks(1).getField(pjTaskStart1)
at
the time of initialization of project, but this results in different
results
on different machines (NA on most, system date on a few)

Thanks,
Binoy
 
S

Steve House [MVP]

What is the actual end result you're trying to achieve here - load a
variable with the actual text used in the current version so you can display
it later or are you trying to create a constant to later compare to see if a
field either contains a date entry or displays "NA" or the local version
equivalent?

If the object is to test whether a date field contains a valid date or is
displaying NA, try the IsDate function. For example, in a project file
containing 1 task, the expression IsDate(ActiveProject.Task(1).ActualFinish)
returns True if a finish date has been entered and False if it's showing NA.
Does that help get you where you need to be?
 
J

John

Binoy said:
Hi Jim,

Thank you for replying.

The suggested workaround however will not work in my case. What I have is a
function which takes a variant (dates) as an argument and then converts it
into a specific date format (which is then returned as a string).

Before I parse the date, I need to verify two conditions on the input
argument,
1) it is not empty
2) it is defined (i.e. not "NA")

I need some way to accomplish (2) which works across all regional
settings/locales. What I am thinking is that I could take this value from
some unused date field in Microsoft Project for comparison.

Please advise.

Thanks in Advance & Merry Xmas,
Binoy
Binoy,
Probably the easiest way to determine if a Project field has a valid
date is by using the IsDate function. If the value in the field,
(including fields with "NA"), can be converted to or is recognized as a
date, the function will return "true". If not, it will return "false".
This should also make the code language independent.

Once you know you have a valid date, you can then do your conversion to
whatever date format you want.

Hope this helps.
John
Project MVP
Jim Aksel said:
I do not know of a universal value or property that you can access. What I
do is try to compare it to something else.
For example, a completed task will have [Finish]=[Actual Finish]. A task
that is not yet finished will have [Actual Finish]="NA" or what ever "NA"
is
for the given language pack.

So, if I want to test if a task is complete, I don't test for [Actual
Finish]="NA" ... Instead I test if [Finish]=[Actual Finish]. For certain
the value of [Finsih] can never equal NA.

However, that gets a little trickier for things like baselines... how do I
know if I have a baseline date? One other thing I found was when testing
for "NA", I recognized that "NA" was either smaller than the smallest
possible date, or larger than the largest possible date so I tested on
that.
However, I found in VBA and VB.NET the logic seems to reverse.

Hope that helped. Post back if you can't work around it.

Jim Aksel, MVP

Binoy said:
Hi,

Can someone kindly let me know how I can retrieve the text that Microsoft
Project uses for empty date fields using VBA, which works across
different
regional settings? For e.g. for a US English installation, the undefined
date
value is displayed as "NA".

Is there any property of the activeProject object that I could use for
this
purpose? Currently, we use activeProject.Tasks(1).getField(pjTaskStart1)
at
the time of initialization of project, but this results in different
results
on different machines (NA on most, system date on a few)

Thanks,
Binoy
 
J

John

Steve House said:
What is the actual end result you're trying to achieve here - load a
variable with the actual text used in the current version so you can display
it later or are you trying to create a constant to later compare to see if a
field either contains a date entry or displays "NA" or the local version
equivalent?

If the object is to test whether a date field contains a valid date or is
displaying NA, try the IsDate function. For example, in a project file
containing 1 task, the expression IsDate(ActiveProject.Task(1).ActualFinish)
returns True if a finish date has been entered and False if it's showing NA.
Does that help get you where you need to be?

Steve,
Sorry, I didn't notice that you suggested the IsDate several hours
before I posted. At least we're thinking along the same lines :)

John
 
B

Binoy

Thanks All.

The isDate function helps to resolve this issue in a language independent
manner. It returns false when the date is NA.

Steve House said:
What is the actual end result you're trying to achieve here - load a
variable with the actual text used in the current version so you can display
it later or are you trying to create a constant to later compare to see if a
field either contains a date entry or displays "NA" or the local version
equivalent?

If the object is to test whether a date field contains a valid date or is
displaying NA, try the IsDate function. For example, in a project file
containing 1 task, the expression IsDate(ActiveProject.Task(1).ActualFinish)
returns True if a finish date has been entered and False if it's showing NA.
Does that help get you where you need to be?
--
Steve House [Project MVP]
MS Project Trainer & Consultant
Visit http://project.mvps.org/faqs.htm for the FAQs


Binoy said:
Hi,

Can someone kindly let me know how I can retrieve the text that Microsoft
Project uses for empty date fields using VBA, which works across different
regional settings? For e.g. for a US English installation, the undefined
date
value is displayed as "NA".

Is there any property of the activeProject object that I could use for
this
purpose? Currently, we use activeProject.Tasks(1).getField(pjTaskStart1)
at
the time of initialization of project, but this results in different
results
on different machines (NA on most, system date on a few)

Thanks,
Binoy
 

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