Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Case Statement 1

Status
Not open for further replies.

TEM3

Technical User
Dec 6, 2004
324
US
Does Crystal Reports 8.5 have a case statement?

I need to test for about 50 possible field values and instead of a long nested if-then formula, I thought a case statement series would be simplier.....

CASE FIELD.Value}= "X"
Y := Y + 1
CASE {FIELD.Value} = "Z"
Q := Q + 1
etc.

ENDCASE


If so, what is the syntax please??
 
I guess you are using variables:

whileprintingrecords;
numbervar Y;
numbervar Q;

//select case syntax begins here:
Select {table.field}
Case "X" : Y := Y + 1
Case "Z" : Q := Q + 1
default : 0;

-LB
 
Have not tried this yet, but before I do:

whileprintingrecords;
numbervar TXFLUN
numbervar TXGHBGBL
numbervar TXCOCAIN
//Three of 50+

Select {ARRESULT.Test Type Code}
Case "TXFLUN" : TXFLUN := TLFLUN + 1
Case "TXGHBGBL" : TXGHBGBL := TXGHBGBL + 1
Case "TXCOCAIN" : TXCOCAIN := TXCOCAIN + 1
default : 0;


The question is: to keep things easy, is there any reason I can't use the field value as my counting variable??

 
Your example should work. Note that you have a typo in the first case result. Should be:

TXFLUN := TXLFLUN + 1

-LB
 
Thanks. And I would have probably looked at that forever trying to figure why it was not working!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top