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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Failed If Else Statement 1

Status
Not open for further replies.

tmozer

Programmer
Sep 11, 2004
66
0
0
US
I am using the following formula form my Group Header Titles:

if {LABREPT.Lab Code} = "C" then "Central Lab" else
if {LABREPT.Lab Code} = "N" then "North Lab" else
if {LABREPT.Lab Code} = "S" then "South Lab" else
if {LABREPT.Lab Code} = "E" then "East Lab"
else "No Lab Assignment"

The first four lines work fine, but it does not fall through and print "No Lab Assignment" for the exceptions. I just get no Group Title at all (the Grouping still works fine).

What am I doing wrong please?
 
if isnull({LABREPT.Lab Code}) then "No Lab Assignment" else
if {LABREPT.Lab Code} = "C" then "Central Lab" else
if {LABREPT.Lab Code} = "N" then "North Lab" else
if {LABREPT.Lab Code} = "S" then "South Lab" else
if {LABREPT.Lab Code} = "E" then "East Lab" else
"Other Lab"

-LB
 
As LB demonstrates, nulls have to declared first.

I might add to his solution a bit:

if
(
isnull({LABREPT.Lab Code})
or
not({LABREPT.Lab Code} in ["C","N","S","E"])
) then
"No Lab Assignment" else
if {LABREPT.Lab Code} = "C" then "Central Lab" else
if {LABREPT.Lab Code} = "N" then "North Lab" else
if {LABREPT.Lab Code} = "S" then "South Lab" else
if {LABREPT.Lab Code} = "E" then "East Lab" else
"Other Lab"

-k
 
Although I am new to Crystal Reports and SQL, I have been a programmer for about 20 years. I have accessed many forums for information, going back to the pre-Internet age of BBS's and message boards.

This formum is the best! You people are very responsive and helpful. Thank you all!
 
This code works great:

if
(
isnull({LABREPT.Lab Code})
or
not({LABREPT.Lab Code} in ["C","N","S","E"])
) then
"No Lab Assignment" else
if {LABREPT.Lab Code} = "C" then "Central Lab" else
if {LABREPT.Lab Code} = "N" then "North Lab" else
if {LABREPT.Lab Code} = "S" then "South Lab" else
if {LABREPT.Lab Code} = "E" then "East Lab" else
"Other Lab"

But now I would like to apply the concept directly to my grouping.

I can determine what the Lab Code should be (for the historical data with missing lab codes) by the Case Number. The logic would be:

If LABCASE.Lab Case starts with N011 the Lab Code would be "C", if N012 - "N", if N013 - "S" and if N014 - "E". So I would want to test for a lab code and, if blank, substitute a lab code generated from the Lab Case Number.


 
Here is my attempt at the formula (called {CalLabCode}).

if
(
isnull({ALL_ASSIGNMENTS.Lab Code})
)
then "No Lab Assignment" else
if "N011" in {LABCASE.Lab Case} then "Central Lab" else
if "N012" in {LABCASE.Lab Case} then "North Lab" else
if "N013" in {LABCASE.Lab Case} then "South Lab" else
if "N014" in {LABCASE.Lab Case} then "East Lab" else
if {ALL_ASSIGNMENTS.Lab Code} = "C" then "Central Lab" else
if {ALL_ASSIGNMENTS.Lab Code} = "N" then "North Lab" else
if {ALL_ASSIGNMENTS.Lab Code} = "S" then "South Lab" else
if {ALL_ASSIGNMENTS.Lab Code} = "E" then "East Lab" else
"Other Lab"

It is not working as expected, but I think I see the problem. I have to take out the "No Lab Assignment" Logic.....
 
You have the first part backwards

if {LABCASE.Lab Case} = "N011" then "Central Lab" else
if {LABCASE.Lab Case} = "N012" then "North Lab" else
if {LABCASE.Lab Case} = "N013" then "South Lab" else
if {LABCASE.Lab Case} = "N014" then "East Lab" else
 
Sorry, not sure what you mean wichitakid??

Anyway, here is what I presently have, but it is not falling through to the second part.....

if {ALL_ASSIGNMENTS.Lab Code} = "C" then "Central Lab" else
if {ALL_ASSIGNMENTS.Lab Code} = "N" then "North Lab" else
if {ALL_ASSIGNMENTS.Lab Code} = "S" then "South Lab" else
if {ALL_ASSIGNMENTS.Lab Code} = "E" then "East Lab" else
if
(
isnull({ALL_ASSIGNMENTS.Lab Code})
)
then
if "N011" in {LABCASE.Lab Case} then "Central Lab" else
if "N012" in {LABCASE.Lab Case} then "North Lab" else
if "N013" in {LABCASE.Lab Case} then "South Lab" else
if "N014" in {LABCASE.Lab Case} then "East Lab" else
"Other Lab"
 
You have to do the null check before you compare the value. So the line:

isnull({ALL_ASSIGNMENTS.Lab Code})

needs to be the very first statement.
 
Thanks lbass. I am a new programmer to Crystal and I was able to solve a logic issue using your Oct 6, 2004 response to tmozer!

What a great forum! I have this bookmarked and I'll be back!
Again Thanks!
dlk
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top