Search code examples
conditional-statementscrystal-reportsformula

Conditional Formula in Crystal Reports?


The code below works but it is not a great way to write.

Is there any better way to achieve it? "{#RTotal}" is a running total.

stringVar Fld := "";
IF ({#RTotal0}=1)
then
 Fld:="A"
ELSE IF ({#RTotal0}=2)
then
Fld:="B"
ELSE IF ({#RTotal0}=3)
then
 Fld:="C"
ELSE IF ({#RTotal0}=4)
then
Fld:="D"
ELSE IF ({#RTotal0}=5)
then
Fld:="E"
ELSE IF ({#RTotal0}=6)
 then
Fld:="F"
ELSE IF ({#RTotal0}=7)
then
Fld:="G"
else
 Fld:="H";

Solution

  • Yes, for more clarity, you can use the CASE..ELSE block;

    select {#RTotal}
     case 1 : "A"
     case 2 : "B" 
    ..