Results 1 to 11 of 11
  1. #1
    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"

  2. #2
    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

  3. #3
    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.

  4. #4
    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.

  5. #5
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,115
    Take a peek at case statements in the help files
    George
    Home | Blog

  6. #6
    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.

  7. #7
    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.

  8. #8
    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"

  9. #9
    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?

  10. #10
    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.

  11. #11
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •