cancel
Showing results for 
Search instead for 
Did you mean: 

If then else

Former Member
0 Kudos

Can anyone suggest why i never get to the Else statement ?

There are many {SRMARRAY.LASTDISCOVERYTIME} that do contain a date and time.

{

stringvar notdiscovered;

stringvar discovered := "discovered ok";

numbervar countofnullarrays;

if isnull({SRMARRAY.LASTDISCOVERYTIME})

Then (countofnullarrays := countofnullarrays+1;

notdiscovered :="NOT DISCOVERED")

Else

discovered :="discovered ok";

}

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

John: I just ran your code in CR XI R2, with the comment marks, and it worked fine. It only worked with parentheses, not braces, however.

I don't think you ever said what version and platform you were using.

Former Member
0 Kudos

cr2008 version 12.3.0.601

Former Member
0 Kudos

Replace the braces {} around the formula with parenthesis ()

Answers (3)

Answers (3)

Former Member
0 Kudos

I haven't looked at the code too closely, but a "//" would only mess you up if you were writing in Basic syntax, not Crystal.

Former Member
0 Kudos

It is Crystal syntax

former_member292966
Active Contributor
0 Kudos

Hi John,

Date and DateTime fields are never NULL in Crystal. A Null date would be Date (0, 0, 0).

{
stringvar notdiscovered;
stringvar discovered := "discovered ok";
numbervar countofnullarrays;

if {SRMARRAY.LASTDISCOVERYTIME} = CDateTime (0, 0, 0)  
Then (countofnullarrays := countofnullarrays+1;
          notdiscovered :="NOT DISCOVERED")
Else 
     discovered :="discovered ok";
}

Good luck,

Brian

Former Member
0 Kudos

All, thanks for the suggestions.

I want to bump a count "countofnullarrays" for later use and the output from the if then else has to be a stringvar to contain "discovered" or "not discovered"

The field srmarray.lastdiscovewrytime is null if there is not a date/time if i add this simple

formaula to my report, it does display that the field contained a null/not null value

{

if isnull({SRMARRAY.LASTDISCOVERYTIME})

then "null"

else "not null"

}

this produces :-

CK200070700577_NCR null

CK200070700577_TSSNCR null

CK200070800687 null

CK200073300421 null

PHX_T3_0340 (NS960_0340) null

PHX_T1_0512 9/10/2010 1:15:53 PM not null

PHX_T1_0515 9/10/2010 1:15:43 PM not null

PHX_T1_4277 9/10/2010 1:15:37 PM not null

PHX_T1_0343 9/10/2010 1:15:28 PM not null

So why is why if then else not working ?

{

stringvar notdiscovered;

stringvar discovered;

numbervar countofnullarrays;

if isnull({SRMARRAY.LASTDISCOVERYTIME})

Then (countofnullarrays := countofnullarrays+1;

notdiscovered :="NOT DISCOVERED")

Else

discovered :="discovered ok";

}

Former Member
0 Kudos

Everyone, the problem is casused by a "//" comment in my code which i had removed before pasting to this forum:

{

stringvar notdiscovered;

stringvar discovered;

numbervar countofnullarrays;

if isnull({SRMARRAY.LASTDISCOVERYTIME})

//then display "not discovered"

Then (countofnullarrays := countofnullarrays+1;

notdiscovered :="NOT DISCOVERED")

Else

//then display"discovered ok"

discovered :="discovered ok";

}

if i remove the "//" comments the code works correctly.

I would suggest this is a bug ??? comments

Former Member
0 Kudos

Brian,

That just is not true. IsNull works perfectly with date fields.

Former Member
0 Kudos

Perhaps because you have the entire statement inside { } ? Don't know why it would make a difference other than { } are used to define a field name, but removing the comments doesn't make sense either Try removing them and see if it makes a difference.

Former Member
0 Kudos

Thanks to all that responded, if i remove the "//" comments the code works.

So is this a bug or not ?

Former Member
0 Kudos

Don't think you can have two declarations in the then

(

stringvar notdiscovered;

stringvar discovered := "discovered ok";

numbervar countofnullarrays;

if isnull({SRMARRAY.LASTDISCOVERYTIME})

Then notdiscovered :="NOT DISCOVERED"

Else

discovered :="discovered ok";

);

countofnullarrays := countofnullarrays+1;

Ian

Former Member
0 Kudos

You bet you can get multiple statements between a single combination of "then" and "else".

You just have to place them between parenthesis "()". Actually, just like he's doing...

John, are you sure that {SRMARRAY.LASTDISCOVERYTIME} does contain null-values when it has never been discovered?

Couldn't it contain just zeros?

Edited by: D. van Gerwen on Sep 10, 2010 3:16 PM