If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Crystal Reports > trouble with nest "IF THEN ELSE"

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old
Registered User
 
Join Date: Sep 2007
Posts: 18
trouble with nest "IF THEN ELSE"

I have a problem where the third ' If then Else' statement will not produce a message. If I move that 'If then Else ' statement up to the first 'If Then Else' position, it works fine but now the one that is in the third nested 'If' won't produce a message. It seems the position of the third or four nested 'If Then Else' just gets thrown away. I am running Crystal 10
----
Whileprintingrecords;
Stringvar message;
If {@warning_one_immediate}="1" then
message := "#I1 Patient Requires Immediate Assessment"
ELSE
If {@warning_two}="2" then
message := "#2 Patient Requires Immediate Assessment"
ELSE
IF {@warning_three} ="3" then
message := "#3 Patient Requires Assessment within 24 hours"
ElSE
message := "Assess within 48 hours"
Reply With Quote
  #2 (permalink)  
Old
Registered User
 
Join Date: May 2003
Location: UK
Posts: 233
What happens if you try

If {@warning_one_immediate}="1" then
message := "#I1 Patient Requires Immediate Assessment"
End If
If {@warning_two}="2" then
message := "#2 Patient Requires Immediate Assessment"
End If
IF {@warning_three} ="3" then
message := "#3 Patient Requires Assessment within 24 hours"
End IF
Reply With Quote
  #3 (permalink)  
Old
Registered User
 
Join Date: Sep 2007
Posts: 18
Thanks for the reply. One or more of these warning could be set but we only want to display the highest level one and then end out. With your proposed if ,then, else it would print a message for each warning if more than one was set. I truly think this is a bug in Crystasl 10 code. Even when testing with only one warning set anything after the second if,the, else will not print. If I move the third warining up to the first if, then, else, it will print the warning message #3.
Reply With Quote
  #4 (permalink)  
Old
Registered User
 
Join Date: May 2003
Location: UK
Posts: 233
If you only want to print the highest warning level with that formula it will take the last If Statement (I thought) so you can put the highest warning as the last If statement.

Or if this warning is the highest within a group could create another formula that looks at the If formula and selects the highest warning level.
Reply With Quote
  #5 (permalink)  
Old
www.gvee.co.uk
 
Join Date: Jan 2007
Location: UK
Posts: 11,002
Take a peek at case statements in the help files
__________________
George
Home | Blog
Reply With Quote
  #6 (permalink)  
Old
Registered User
 
Join Date: Sep 2007
Posts: 18
Unforunately I can't get the nested if,then,else to go beyond the second set of statements so moving the highest to the last won't work.

Your second suggestion about the group, I am not sure I understand. I thought that was what I was doing by my nested if,then,else statements.

Hi George
Thanks
I need look at the help files. That is what helped me get as far as I have so far.
Reply With Quote
  #7 (permalink)  
Old
Registered User
 
Join Date: Oct 2005
Posts: 178
Your original IF -ELSE-End statement will evaluate each record but will only display the last record. Using the IF-End will display all conditions that are met. Two things you can do.
Sort your records in ascending with the field of interest before your IF-ELSE-End statements. Or use a variable to store highest value by comparing succeeding records value, the use that IF-ELSE-END statement.
Reply With Quote
  #8 (permalink)  
Old
Registered User
 
Join Date: Sep 2007
Posts: 18
Thanks for your reply.

I believe I understand what you are saying when I have all the warnings set. But even when I run the nested if statements and I only have one warning set (for the third warning message) , it will not print it.

If I move the third warning up from the third if,then,else to the first if,then,else it will print the message. When does it stop looking at any of the conditions after the second set of if,then,else statements.

compare this code that works against the original code I sent on the first request.
Whileprintingrecords;
STRINGVAR MSG;
IF {@warning_three} = "2" then
MSG := "#3 Patient Requires Immediate Assessment"
ELSE
IF {@warning_two}= "2" then
MSG := "#2 Patient Requires Immediate Assessment"
Else
IF {@warning_one_immediate}= "1" then
MSG := "#I1 Patient Requires Immediate Assessment"
else
MSG := "all the Way through"
Reply With Quote
  #9 (permalink)  
Old
Registered User
 
Join Date: May 2003
Location: UK
Posts: 233
Quote:
Originally Posted by georgev
Take a peek at case statements in the help files

Is it possible to use case statements against different fields?
Reply With Quote
  #10 (permalink)  
Old
Registered User
 
Join Date: Jan 2008
Location: Mississippi
Posts: 7
This may not be any help at all, but I have found that in Crystal you need to check the field for null values before doing anything to that field. For instance:

if not isnull(field1)
then
(
if field1 = "this"
then
(
display := "this";
)
else if field1 = "that"
then
(
display := "that";
)
else
(
display := "whatever";
);
);

Like I said this may or may not work bit it might be worth a try.
Reply With Quote
  #11 (permalink)  
Old
Registered User
 
Join Date: Sep 2007
Posts: 18
thanks LindaVRMS

I have tried doing the null value checking and still nothing after the second nested if then else will execute. I am going to unload the latest service pak for my release and see if that helps.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On