Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Variable assignment in if statement

Status
Not open for further replies.

jfcox

Programmer
Jul 11, 2001
44
US
I'm trying to use the if statement below to change the output if the value is null. When I run the report, it crashes and says the formula is invalid. In fooling around with it, it appears that the if statement is working so I though it might be a problem creating variables inside the if. I've tried defining the variable first and outside of the if statement with the same results.
Can someone please tell me why?

Here's the code:

If Not IsNull({TRANSITION_MASTER.ACTIONDATEM20}) or
Length({TRANSITION_MASTER.ACTIONDATEM20}) > 0 or
NUMERICTEXT({TRANSITION_MASTER.ACTIONDATEM20})

then (
Local NumberVar ActYr := ToNumber({TRANSITION_MASTER.ACTIONDATEY20});
Local NumberVar ActMo := ToNumber({TRANSITION_MASTER.ACTIONDATEM20});
Local NumberVar ActDay := ToNumber({TRANSITION_MASTER.ACTIONDATED20});

Local DateVar ActDate := Cdate(ActYr,ActMo,ActDay);
)
ELSE
(
Local DateVar ActDate := CurrentDate;
)
 
If you preface your code with "WhilePrintingRecords;", does that change anything?

Software Sales, Training, Implementation and Support for Exact Macola, eSynergy, and Crystal Reports
dgilsdorf@trianglepartners.com
 
Good thought and thanks, but that didn't do it. Is Crystal trying to evaluate the variable before it read's the IF statement? Have I confused local and global variable definitiions somehow?

thanks
 
Change your "OR" to "AND"...all of these conditions must exist...

If Not IsNull({TRANSITION_MASTER.ACTIONDATEM20}) AND
Length({TRANSITION_MASTER.ACTIONDATEM20}) > 0 AND
NUMERICTEXT({TRANSITION_MASTER.ACTIONDATEM20})

then (
Local NumberVar ActYr := ToNumber({TRANSITION_MASTER.ACTIONDATEY20});
Local NumberVar ActMo := ToNumber({TRANSITION_MASTER.ACTIONDATEM20});
Local NumberVar ActDay := ToNumber({TRANSITION_MASTER.ACTIONDATED20});

Local DateVar ActDate := Cdate(ActYr,ActMo,ActDay);
)
ELSE
(
Local DateVar ActDate := CurrentDate;
);


Some days...I hate boolean logic :)





Jim Broadbent
 
That worked! I don't understand why the 'or' wouldn't work but I'll take what I can get.

Thanks for your help.

Jim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top