Solved

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

Posted on 2004-09-21
6
972 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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

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…
There have always been a lot of questions related to when Crystal Reports evaluates report components (such as formulas, summaries, cross-tabs, charts, to name a few examples). Crystal Reports uses a two-pass reporting process to provide greater …
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

746 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now