Report Design
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Report Design
Message Icon Topic: Uninitialised variables Post Reply Post New Topic
Author Message
jrisch
Newbie
Newbie


Joined: 10 Mar 2008
Location: United Kingdom
Online Status: Offline
Posts: 9
Quote jrisch Replybullet Topic: Uninitialised variables
     Posted: 13 Apr 2011 at 7:30am
Is it possible to test a global variable, especially a datetime variable, to see if it is initialised, similar to an IsNull or an IsEmpty type function? Or do I need to pre-initialise it with a dummy value, such as 1/1/1900, and test for that?

The accompanying question, is it possible to return a variable to an uninitialised state?

Regards, John
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 14 Apr 2011 at 3:12am
hadn't thought about it.  Looking at CR Help, uninitialized variables will have the default value for its type.
 
So all will have default values.  They may be empty, as I would guess that a string would be empty, but number probably initialize to 0.  I wouldn't know a date, but that should be pretty easy determine.
 
local datetimevar aDate;
aDate
 
and see what you get.
 
Setting to a dummy date would probably be the easiest, but it might be same 1/1/1900.
 
HTH
IP IP Logged
jrisch
Newbie
Newbie


Joined: 10 Mar 2008
Location: United Kingdom
Online Status: Offline
Posts: 9
Quote jrisch Replybullet Posted: 14 Apr 2011 at 11:55am
Thanks. I should have pointed out that I'd tried the obvious.A datetime displays as blank, numbers display as zero, strings are empty strings. So I can test a StringVar for "", and test a NumberVar for 0, but don't know what I can test a DateTimeVar for. It's not #01/01/1900#, or #31/12/1899#
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 15 Apr 2011 at 3:17am
well, that is a bit tricky.
 
Here is what I did...not the brightest, and there is probably a better way...
 
in the formula that you want to compare, add:
local datetimevar emptyDate;
 
if SharedVariable = emptyDate then
...
else
...
 
and of course you can reset the SharedVariable to the local variable to get the initialized value.  What is it? Don't know, but as long as works...since it gets my report done and the management is happy, and that is the goal...isn't it?
 
HTH
IP IP Logged
jrisch
Newbie
Newbie


Joined: 10 Mar 2008
Location: United Kingdom
Online Status: Offline
Posts: 9
Quote jrisch Replybullet Posted: 15 Apr 2011 at 7:53am
That's quite a neat idea, especially as I have a number of dates and that only requires the empty one defining once.

Thanks.
IP IP Logged
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum