cancel
Showing results for 
Search instead for 
Did you mean: 

IF Else nesting in Crystal report

Former Member
0 Kudos

Hello Expert,

Please help me with this. i have following If else in my crystal report 2008 and it only considers first IF condition and ignores rest of ifs.

IF {CCS_ScheduleMatrixRpt;1.period4} [(InStr ({CCS_ScheduleMatrixRpt;1.period4}, ";") - 1)] = "4" Then

{CCS_ScheduleMatrixRpt;1.period4} [(InStr ({CCS_ScheduleMatrixRpt;1.period4}, " ") + 1) To Length ({CCS_ScheduleMatrixRpt;1.period4})]

ELSE IF {CCS_ScheduleMatrixRpt;1.period2} [(InStr ({CCS_ScheduleMatrixRpt;1.period2}, ";") - 1)] = "4" Then

{CCS_ScheduleMatrixRpt;1.period2} [(InStr ({CCS_ScheduleMatrixRpt;1.period2}, " ") + 1) To Length ({CCS_ScheduleMatrixRpt;1.period2})]

ELSE IF {CCS_ScheduleMatrixRpt;1.period3} [(InStr ({CCS_ScheduleMatrixRpt;1.period3}, ";") - 1)] = "4" Then

{CCS_ScheduleMatrixRpt;1.period3} [(InStr ({CCS_ScheduleMatrixRpt;1.period3}, " ") + 1) To Length ({CCS_ScheduleMatrixRpt;1.period3})]

ELSE IF {CCS_ScheduleMatrixRpt;1.period5} [(InStr ({CCS_ScheduleMatrixRpt;1.period5}, ";") - 1)] = "4" Then

{CCS_ScheduleMatrixRpt;1.period5} [(InStr ({CCS_ScheduleMatrixRpt;1.period5}, " ") + 1) To Length ({CCS_ScheduleMatrixRpt;1.period5})]

ELSE IF {CCS_ScheduleMatrixRpt;1.period1} [(InStr ({CCS_ScheduleMatrixRpt;1.period1}, ";") - 1)] = "4" Then

{CCS_ScheduleMatrixRpt;1.period1} [(InStr ({CCS_ScheduleMatrixRpt;1.period1}, " ") + 1) To Length ({CCS_ScheduleMatrixRpt;1.period1})]

ELSE IF {CCS_ScheduleMatrixRpt;1.period6} [(InStr ({CCS_ScheduleMatrixRpt;1.period6}, ";") - 1)] = "4" Then

{CCS_ScheduleMatrixRpt;1.period6} [(InStr ({CCS_ScheduleMatrixRpt;1.period6}, " ") + 1) To Length ({CCS_ScheduleMatrixRpt;1.period6})]

ELSE IF {CCS_ScheduleMatrixRpt;1.period7} [(InStr ({CCS_ScheduleMatrixRpt;1.period7}, ";") - 1)] = "4" Then

{CCS_ScheduleMatrixRpt;1.period7} [(InStr ({CCS_ScheduleMatrixRpt;1.period7}, " ") + 1) To Length ({CCS_ScheduleMatrixRpt;1.period7})]

ELSE IF {CCS_ScheduleMatrixRpt;1.period8} [(InStr ({CCS_ScheduleMatrixRpt;1.period8}, ";") - 1)] = "4" Then

{CCS_ScheduleMatrixRpt;1.period8} [(InStr ({CCS_ScheduleMatrixRpt;1.period8}, " ") + 1) To Length ({CCS_ScheduleMatrixRpt;1.period8})]

Please please help me here have spent so many hours on this...

Thanks in advance

Regards,

H

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi,

Try this: Did you mean this one

IF {CCS_ScheduleMatrixRpt;1.period4} [(InStr ({CCS_ScheduleMatrixRpt;1.period4}, ";") - 1)] = "4"

Then

{CCS_ScheduleMatrixRpt;1.period4} [(InStr ({CCS_ScheduleMatrixRpt;1.period4}, " ") + 1) To Length ({CCS_ScheduleMatrixRpt;1.period4})]

Thanks,

DJ

Former Member
0 Kudos

thanks DJ but i want other IF condition as well i am checking 8 diffrent field if it has first charcter as  "4" then display rest of the value from that field

abhilash_kumar
Active Contributor
0 Kudos

What exactly are you trying to achieve?

If the first IF evaluates to True it will skip the rest.

-Abhilash

DellSC
Active Contributor
0 Kudos

Here's an example of how it could be done using a case/switch statement:

NumberVar atSemiP8 := InStr({CCS_ScheduleMatrixRpt;1.period8}, ";") - 1;
NumberVar atSemiP7 := InStr({CCS_ScheduleMatrixRpt;1.period7}, ";") - 1;
NumberVar atSemiP6 := InStr({CCS_ScheduleMatrixRpt;1.period6}, ";") - 1;
NumberVar atSemiP5 := InStr({CCS_ScheduleMatrixRpt;1.period5}, ";") - 1;
NumberVar atSemiP4 := InStr({CCS_ScheduleMatrixRpt;1.period4}, ";") - 1;
NumberVar atSemiP3 := InStr({CCS_ScheduleMatrixRpt;1.period3}, ";") - 1;
NumberVar atSemiP2 := InStr({CCS_ScheduleMatrixRpt;1.period2}, ";") - 1;
NumberVar atSemiP1 := InStr({CCS_ScheduleMatrixRpt;1.period1}, ";") - 1;

Switch(
  {CCS_ScheduleMatrixRpt;1.period4}[atSemiP4] = "4", {CCS_ScheduleMatrixRpt;1.period4}[(InStr({CCS_ScheduleMatrixRpt;1.period4}, " ") + 1) To Length({CCS_ScheduleMatrixRpt;1.period4})],
  {CCS_ScheduleMatrixRpt;1.period2}[atSemiP2] = "4", {CCS_ScheduleMatrixRpt;1.period2}[(InStr({CCS_ScheduleMatrixRpt;1.period2}, " ") + 1) To Length({CCS_ScheduleMatrixRpt;1.period2})],
  {CCS_ScheduleMatrixRpt;1.period3}[atSemiP3] = "4", {CCS_ScheduleMatrixRpt;1.period3}[(InStr({CCS_ScheduleMatrixRpt;1.period3}, " ") + 1) To Length({CCS_ScheduleMatrixRpt;1.period3})],
  {CCS_ScheduleMatrixRpt;1.period5}[atSemiP5] = "4", {CCS_ScheduleMatrixRpt;1.period5}[(InStr({CCS_ScheduleMatrixRpt;1.period5}, " ") + 1) To Length({CCS_ScheduleMatrixRpt;1.period5})],
  {CCS_ScheduleMatrixRpt;1.period1}[atSemiP1] = "4", {CCS_ScheduleMatrixRpt;1.period1}[(InStr({CCS_ScheduleMatrixRpt;1.period1}, " ") + 1) To Length({CCS_ScheduleMatrixRpt;1.period1})],
  {CCS_ScheduleMatrixRpt;1.period6}[atSemiP6] = "4", {CCS_ScheduleMatrixRpt;1.period6}[(InStr({CCS_ScheduleMatrixRpt;1.period6}, " ") + 1) To Length({CCS_ScheduleMatrixRpt;1.period6})],
  {CCS_ScheduleMatrixRpt;1.period7}[atSemiP7] = "4", {CCS_ScheduleMatrixRpt;1.period7}[(InStr({CCS_ScheduleMatrixRpt;1.period7}, " ") + 1) To Length({CCS_ScheduleMatrixRpt;1.period7})],
  {CCS_ScheduleMatrixRpt;1.period8}[atSemiP8] = "4", {CCS_ScheduleMatrixRpt;1.period8}[(InStr({CCS_ScheduleMatrixRpt;1.period8}, " ") + 1) To Length({CCS_ScheduleMatrixRpt;1.period8})],
  true, ""
)

However, as Abhilash stated, this will only process as far as the first "true" result in the comparison.  So, if you want to process all 8 periods so that you can display each on your report, you'll need to do a separate formula for each period in order to get the correct value for each of them.

-Dell

Former Member
0 Kudos

i tried it it doesn't look like it worked but i am going to play around with it and try it agian on monday thanks Dell your answer is helpful.

Former Member
0 Kudos

Hi,

Try this:

If

(

{CCS_ScheduleMatrixRpt;1.period4} [(InStr ({CCS_ScheduleMatrixRpt;1.period4}, ";") - 1)] = "4"

or  {CCS_ScheduleMatrixRpt;1.period2} [(InStr ({CCS_ScheduleMatrixRpt;1.period2}, ";") - 1)] = "4"

or  {CCS_ScheduleMatrixRpt;1.period3} [(InStr ({CCS_ScheduleMatrixRpt;1.period3}, ";") - 1)] = "4"

or  {CCS_ScheduleMatrixRpt;1.period5} [(InStr ({CCS_ScheduleMatrixRpt;1.period5}, ";") - 1)] = "4"

or  {CCS_ScheduleMatrixRpt;1.period1} [(InStr ({CCS_ScheduleMatrixRpt;1.period1}, ";") - 1)] = "4"

or  {CCS_ScheduleMatrixRpt;1.period6} [(InStr ({CCS_ScheduleMatrixRpt;1.period6}, ";") - 1)] = "4"

or  {CCS_ScheduleMatrixRpt;1.period7} [(InStr ({CCS_ScheduleMatrixRpt;1.period7}, ";") - 1)] = "4"

or  {CCS_ScheduleMatrixRpt;1.period8} [(InStr ({CCS_ScheduleMatrixRpt;1.period8}, ";") - 1)] = "4"

)

else if

(

  {CCS_ScheduleMatrixRpt;1.period4}[atSemiP4] = "4", {CCS_ScheduleMatrixRpt;1.period4}[(InStr({CCS_ScheduleMatrixRpt;1.period4}, " ") + 1) To Length({CCS_ScheduleMatrixRpt;1.period4})] or

  {CCS_ScheduleMatrixRpt;1.period2}[atSemiP2] = "4", {CCS_ScheduleMatrixRpt;1.period2}[(InStr({CCS_ScheduleMatrixRpt;1.period2}, " ") + 1) To Length({CCS_ScheduleMatrixRpt;1.period2})] or

  {CCS_ScheduleMatrixRpt;1.period3}[atSemiP3] = "4", {CCS_ScheduleMatrixRpt;1.period3}[(InStr({CCS_ScheduleMatrixRpt;1.period3}, " ") + 1) To Length({CCS_ScheduleMatrixRpt;1.period3})] or

  {CCS_ScheduleMatrixRpt;1.period5}[atSemiP5] = "4", {CCS_ScheduleMatrixRpt;1.period5}[(InStr({CCS_ScheduleMatrixRpt;1.period5}, " ") + 1) To Length({CCS_ScheduleMatrixRpt;1.period5})] or

  {CCS_ScheduleMatrixRpt;1.period1}[atSemiP1] = "4", {CCS_ScheduleMatrixRpt;1.period1}[(InStr({CCS_ScheduleMatrixRpt;1.period1}, " ") + 1) To Length({CCS_ScheduleMatrixRpt;1.period1})] or

  {CCS_ScheduleMatrixRpt;1.period6}[atSemiP6] = "4", {CCS_ScheduleMatrixRpt;1.period6}[(InStr({CCS_ScheduleMatrixRpt;1.period6}, " ") + 1) To Length({CCS_ScheduleMatrixRpt;1.period6})] or

  {CCS_ScheduleMatrixRpt;1.period7}[atSemiP7] = "4", {CCS_ScheduleMatrixRpt;1.period7}[(InStr({CCS_ScheduleMatrixRpt;1.period7}, " ") + 1) To Length({CCS_ScheduleMatrixRpt;1.period7})] or

  {CCS_ScheduleMatrixRpt;1.period8}[atSemiP8] = "4", {CCS_ScheduleMatrixRpt;1.period8}[(InStr({CCS_ScheduleMatrixRpt;1.period8}, " ") + 1) To Length({CCS_ScheduleMatrixRpt;1.period8})]

}

Am not sure see how this happens...

--dj

former_member292966
Active Contributor
0 Kudos

Hi H,

After each Then statement, terminate it with ";".  Without the termination, Crystal thinks the rest of the statement is all part of the first Else.  Like a paragraph without a period, it all becomes one long run-on sentence.

IF {CCS_ScheduleMatrixRpt;1.period4} [(InStr ({CCS_ScheduleMatrixRpt;1.period4}, ";") - 1)] = "4" Then

{CCS_ScheduleMatrixRpt;1.period4} [(InStr ({CCS_ScheduleMatrixRpt;1.period4}, " ") + 1) To Length ({CCS_ScheduleMatrixRpt;1.period4})];

ELSE IF {CCS_ScheduleMatrixRpt;1.period2} [(InStr ({CCS_ScheduleMatrixRpt;1.period2}, ";") - 1)] = "4" Then

{CCS_ScheduleMatrixRpt;1.period2} [(InStr ({CCS_ScheduleMatrixRpt;1.period2}, " ") + 1) To Length ({CCS_ScheduleMatrixRpt;1.period2})];

ELSE IF {CCS_ScheduleMatrixRpt;1.period3} [(InStr ({CCS_ScheduleMatrixRpt;1.period3}, ";") - 1)] = "4" Then

{CCS_ScheduleMatrixRpt;1.period3} [(InStr ({CCS_ScheduleMatrixRpt;1.period3}, " ") + 1) To Length ({CCS_ScheduleMatrixRpt;1.period3})];

ELSE IF {CCS_ScheduleMatrixRpt;1.period5} [(InStr ({CCS_ScheduleMatrixRpt;1.period5}, ";") - 1)] = "4" Then

{CCS_ScheduleMatrixRpt;1.period5} [(InStr ({CCS_ScheduleMatrixRpt;1.period5}, " ") + 1) To Length ({CCS_ScheduleMatrixRpt;1.period5})];

ELSE IF {CCS_ScheduleMatrixRpt;1.period1} [(InStr ({CCS_ScheduleMatrixRpt;1.period1}, ";") - 1)] = "4" Then

{CCS_ScheduleMatrixRpt;1.period1} [(InStr ({CCS_ScheduleMatrixRpt;1.period1}, " ") + 1) To Length ({CCS_ScheduleMatrixRpt;1.period1})];

ELSE IF {CCS_ScheduleMatrixRpt;1.period6} [(InStr ({CCS_ScheduleMatrixRpt;1.period6}, ";") - 1)] = "4" Then

{CCS_ScheduleMatrixRpt;1.period6} [(InStr ({CCS_ScheduleMatrixRpt;1.period6}, " ") + 1) To Length ({CCS_ScheduleMatrixRpt;1.period6})];

ELSE IF {CCS_ScheduleMatrixRpt;1.period7} [(InStr ({CCS_ScheduleMatrixRpt;1.period7}, ";") - 1)] = "4" Then

{CCS_ScheduleMatrixRpt;1.period7} [(InStr ({CCS_ScheduleMatrixRpt;1.period7}, " ") + 1) To Length ({CCS_ScheduleMatrixRpt;1.period7})];

ELSE IF {CCS_ScheduleMatrixRpt;1.period8} [(InStr ({CCS_ScheduleMatrixRpt;1.period8}, ";") - 1)] = "4" Then

{CCS_ScheduleMatrixRpt;1.period8} [(InStr ({CCS_ScheduleMatrixRpt;1.period8}, " ") + 1) To Length ({CCS_ScheduleMatrixRpt;1.period8})];

Thanks,

Brian

abhilash_kumar
Active Contributor
0 Kudos

I don't think that'll work, Brian.

You cannot end an If..then with a semicolon when you have an 'else if' that follows.

-Abhilash

former_member292966
Active Contributor
0 Kudos

Hi Abhilash,

You're right.  I was trying to avoid the ugly encapsulating everything within parentheses.  With a nested If...Else this large it will get really complicated really fast.

A Case statement would be preferable but I can't see it being used here.

Former Member
0 Kudos

Thanks Brian. But as Abhilash mentioned it shows me an error message "The remaining text doesnt appear to be the part of formula"

Any other suggestions???