Solved

How do I reset Global DateTimeVar to Null (Empty/Blank)?

Posted on 2004-09-21
6
1,043 Views
Last Modified: 2008-01-16
Quick question --

How do I reset a global DateTime variable to null/empty/blank? If it's a number, that's easy. But what about if it's a datetime variable?

For instance, I have the following formula (DisplayInst) which evaluates at a group footer:

WhilePrintingRecords; Global DatetimeVar InstVar

This displays the Datetime variable "InstVar" which is created earlier in the details section with the following formula (CalcInst):

WhilePrintingRecords;
If InStr({_Custom__rptUpgradedClients_1.Name},{?NewVersion}) > 0 then
Global DateTimeVar InstVar := {_Custom__rptUpgradedClients_1.InstallDate}

The variable compares a product name field with a version parameter field. If successful, it updates the InstVar variable with an install date. This works fine until it reaches a record that has a null _Custom_rptUpgradedClients_1.InstallDate from the SQL table. When this occurs, the Global InstVar is still the same as the previous record, so it prints the previous record's Install Date.

I was thinking something like:

WhilePrintingRecords;
If InStr({_Custom__rptUpgradedClients_1.Name},{?NewVersion}) > 0 then
Global DateTimeVar InstVar := {_Custom__rptUpgradedClients_1.InstallDate}
else
Global DateTimeVar InstVar := NULL, Empty, Blank, 0, etc...

but I'm not sure of the syntax on how to empty the variable.

I'm actually pretty sure the above solution would bring problems. I was thinking I needed to reset the variable each time the group is passed. But again, I need to know how to empty the variable.

I'm a newbile when it comes to this, so any help would be greatly appreciated :) Thanks!
0
Comment
Question by:eledol
  • 2
  • 2
6 Comments
 
LVL 28

Accepted Solution

by:
bdreed35 earned 250 total points
ID: 12114989
You are better off creating a out of range date instead of trying to set it to NULL:

WhilePrintingRecords;
If Isnull(({_Custom__rptUpgradedClients_1.Name})  or InStr({_Custom__rptUpgradedClients_1.Name},{?NewVersion}) = 0 then
    Global DateTimeVar InstVar := cdate(1800,1,1)
else
    Global DateTimeVar InstVar := {_Custom__rptUpgradedClients_1.InstallDate}

You can then test for the out of range date value in another formula, or suppress the field when it equals cdate(1800,1,1).
0
 
LVL 42

Assisted Solution

by:frodoman
frodoman earned 250 total points
ID: 12115555
Date (0, 0, 0) is the "null" date value so to set a date to null you can use: cdate(0,0,0)

You can find this and other types by searching help for "default values for the simple types"

frodoman
0
 
LVL 28

Expert Comment

by:bdreed35
ID: 12115672
Good point frodoman.

Using the NULL date value, you can alter the formula I gave you to this:

WhilePrintingRecords;
If Isnull(({_Custom__rptUpgradedClients_1.Name})  or InStr({_Custom__rptUpgradedClients_1.Name},{?NewVersion}) = 0 then
    Global DateTimeVar InstVar := cdate(0,0,0)
else
    Global DateTimeVar InstVar := {_Custom__rptUpgradedClients_1.InstallDate}

This works well if you are using this to display.  You won't need to suppress the field because cdate(0,0,0) will display as a blank field.

One thing to note, I tried using the IsNull() function on a formula that had the value cdate(0,0,0), and the result was false.  I was expecting a true value since the help files say that it is the NULL date value.
So, even if you set it to a null date, you will still need to test for cdate(0,0,0) since Crystal doesn't seem to look at it as NULL, except for display purposes.
0
 
LVL 42

Expert Comment

by:frodoman
ID: 12115781
I agree w/ everything Brian said.  

Testing for 0,0,0 probably makes the code more understandable and there's no chance of an actual date conflicting -- hopefully that's not an issue with Jan 1800 either though :-)
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Crystal Reports: 5 Tests for Top Performance It is complete, your masterpiece report.  Not only does it meet your customer’s expectations, it blows them out the water, all they want is beautifully summarised and displayed in a myriad of ways. …
I hate sub reports and always consider them the last resort in any reporting solution.  The negative effect on performance and maintainability is just not worth the easy ride they give the report writer.  Nine times out of ten reporting requirements…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question