Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: If statements help Post Reply Post New Topic
Author Message
swatts
Groupie
Groupie
Avatar

Joined: 17 Mar 2010
Online Status: Offline
Posts: 83
Quote swatts Replybullet Topic: If statements help
     Posted: 08 Aug 2012 at 9:36am
I am trying to write 1 formula to do this instead of 7 different formulas in 7 different sections suppressed if blank.

If "1" in (Field1) then
"Orange"

but also if "2" in (Field1) then
"Red"

but again if "3" in (Field1) then
also put "Green"
etc

If I use an else statement, of course, if the next if is true it will wipe out the last if and "&" seems to not work because it's if all is inclusive.
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 08 Aug 2012 at 9:51am
not exactly sure that I follow your need here but I think you want something like
 
(If "1" in (Field1) then "Orange ") +
(if "2" in (Field1) then "Red ") +
( if "3" in (Field1) then"Green ")+...


Edited by DBlank - 08 Aug 2012 at 9:52am
IP IP Logged
swatts
Groupie
Groupie
Avatar

Joined: 17 Mar 2010
Online Status: Offline
Posts: 83
Quote swatts Replybullet Posted: 08 Aug 2012 at 9:59am
I think we had tried that before and it didn't work. I tried it just now and it didn't work.
If I use 'else' then red replaces orange and green replaces red, and I want it to just put them there along with the previous.
If I use '&' it looks like it is saying if all of these aren't in here then do not put any of these in here.
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 08 Aug 2012 at 10:06am

Use parenths around each unique if with no else portion and combine each parenthed item with a +....

(If "1" in (Field1) then "Orange ") +
(if "2" in (Field1) then "Red ") +
( if "3" in (Field1) then"Green ") +...
 
 
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 08 Aug 2012 at 10:16am
technically the parenth are not needed but I use them to keep track of each individual statement and you can replace the + with & if you prefer
IP IP Logged
swatts
Groupie
Groupie
Avatar

Joined: 17 Mar 2010
Online Status: Offline
Posts: 83
Quote swatts Replybullet Posted: 08 Aug 2012 at 10:19am
I added the parenthesis and it works now!!!! Thank you.
IP IP Logged
swatts
Groupie
Groupie
Avatar

Joined: 17 Mar 2010
Online Status: Offline
Posts: 83
Quote swatts Replybullet Posted: 29 Nov 2012 at 5:01am
Ugh, now this isn't working. This formula:
if "1" in ({Review.Level_I_Out_Serv_Value}) then
"1. Meeting in lunchroom:" & Chr(13)
+
if "2" in ({Review.Level_I_Out_Serv_Value}) then
"2. Meeting in classroom 4."
& Chr(13)
+
if "3" in ({Review.Level_I_Out_Serv_Value}) then
"3. Meeting in classroom 200."
& Chr(13)
+
if "4" in ({Review.Level_I_Out_Serv_Value}) then
"4. Meeting at town hall."
& Chr(13)
+
if "5" in (Review.Level_I_Out_Serv_Value}) then
"5. No meeting scheduled" & Chr(13)




If I don't pick "1" then I do get any data returned. Any ideas? Am I missing something?

IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 29 Nov 2012 at 5:08am
hmmm... I thought the parenth were not mandatory here but I guess they are.
 
(if "1" in ({Review.Level_I_Out_Serv_Value}) then
"1. Meeting in lunchroom:" & Chr(13))
+
(if "2" in ({Review.Level_I_Out_Serv_Value}) then
"2. Meeting in classroom 4." & Chr(13))
+
(if "3" in ({Review.Level_I_Out_Serv_Value}) then
"3. Meeting in classroom 200." & Chr(13))
+
(if "4" in ({Review.Level_I_Out_Serv_Value}) then
"4. Meeting at town hall." & Chr(13))
+
(if "5" in ({Review.Level_I_Out_Serv_Value}) then
"5. No meeting scheduled" & Chr(13))


Edited by DBlank - 29 Nov 2012 at 5:09am
IP IP Logged
swatts
Groupie
Groupie
Avatar

Joined: 17 Mar 2010
Online Status: Offline
Posts: 83
Quote swatts Replybullet Posted: 29 Nov 2012 at 5:39am
Well, I had them on and it didn't work so I took them off. Now that I added them back, it works!

IP IP Logged
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum