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 John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using Select Case statement ...

Status
Not open for further replies.

Ajith2002

Programmer
Jul 16, 2002
30
US

How do I use Select Case Statements in CR8 ?

This is what I wanted to do -


stringVar Rating;
numberVar avgDays := {@Avg Days - New};

Select Case avgDays
Case >= 5 // <---What is the right way to do this ?
Rating := &quot;Bad&quot;
Case >= 3
Rating := &quot;Fair&quot;
Case >= 2
Rating := &quot;Good&quot;
End Select

Any leads ??
Thanks very much in advance.
 
If you're using relational operators like &quot;>&quot;, and &quot;<&quot; you have to use If/Then/Else.

Like:

If avgDays >= 5
Then Rating := &quot;Bad&quot;
Else...

For the record, correct Case syntax is:

Select {Country}
Case &quot;England&quot; : &quot;Hi&quot;
Case &quot;France&quot; : &quot;Bonsoir&quot;
Case &quot;USA&quot; : &quot;'Sup&quot;
Default : &quot;Hello&quot;

The default is optional.

Naith

 
I'm not absolutely sure but since I only have cr7 here...but I think a relational operator it shuld work

the major thing is you were missing a colon after the case and it is just select...not select case and there is no End Select...a semi colon shows this. A default should be added to catch non-matches

try this

stringVar Rating;
numberVar avgDays := {@Avg Days - New};

Select avgDays
Case >= 5:
Rating := &quot;Bad&quot;
Case >= 3:
Rating := &quot;Fair&quot;
Case >= 2:
Rating := &quot;Good&quot;
Default: // this was added by me
Rating := &quot;Very Good&quot;;

Rating;

Jim Broadbent
 
Dear Ajith2002,

Jim, when I do the above it doesn't work. The first item after case must be a value.

However, looking at what he wrote the following formula works as I just tested and I think gives the results that Ajith2002 is looking for:

//begin formula
stringVar Rating;
numberVar avgDays := {@test};

Select avgDays
Case 3,4: Rating := &quot;Fair&quot; //also valid Case 3 to 4
Case 2: Rating := &quot;Good&quot;
Case 1: Rating := &quot;Very Good&quot;
Default: Rating := &quot;Bad&quot;); //case 5 or higher (ro)

Rating;
//end formula


ro
Rosemary Lieberman
rosemary@microflo.com, Microflo provides expert consulting on MagicTSD and Crystal Reports.
 


It didnt work Jim. I was getting the msg &quot;A number,currency amount,boolean,date,time,date-time, or string is expected here.&quot;
on the line - Case >= 5:

Naith, I wanted to check for 3-4 values of avgDays, for rating. So I need to go for nested If statements. Could pls tell me how to do that using Crystal Reports 8 ? Pls tell me how to put the below select-case statements to If/else statements.

Select avgDays
Case >= 5:
Rating := &quot;Bad&quot;
Case >= 3:
Rating := &quot;Fair&quot;
Case >= 2:
Rating := &quot;Good&quot;
Rating;


Rosemary, I need to check for avgDays greater than or equal to a value.

Thanks very much.
 
Dear Ajith2002;

Here you go:

//begin formula
stringVar Rating;
numberVar avgDays := {@test};

(if avgdays >= 5 then Rating := &quot;Bad&quot;
else if
avgdays >= 3 then Rating := &quot;Fair&quot;
else if avgdays >= 2 then Rating := &quot;Good&quot;
);
Rating;
//end formula

However, I am not sure I understand what your are doing. IF the rating is 1 you get no value at all.

I ran above formula on a report that has a number of days 1 to 180 can be in the value and I get fumky results.

For example

@TestDays Rating
1 &quot;&quot;
2 Good
3 Fair
1 Fair
5 Bad
8 Bad
2 Good
1 Good

So that is why I am wondering about the purpose of your formula as stated.

ro Rosemary Lieberman
rosemary@microflo.com, Microflo provides expert consulting on MagicTSD and Crystal Reports.
 
for relational use in a case select

would it work if we used &quot;is&quot; before the relational operator

stringVar Rating;
numberVar avgDays := {@Avg Days - New};

Select avgDays
Select avgDays
Case is >= 5:
Rating := &quot;Bad&quot;
Case is >= 3:
Rating := &quot;Fair&quot;
Case is >= 2:
Rating := &quot;Good&quot;
Default: // this was added by me
Rating := &quot;Very Good&quot;;

I might be dreaming but I though that relational operators were allowed somehow...perhaps no....a nested If would probably work just as well as Rosemary showed

Jim Broadbent
 
Ajith,

Rosemary's example of an If/Then/Else formula should set you straight. You could also use her Case example, as your range is pretty small.

Jim, you can't be using operators in Crystal's take on case. Some environments support relational case arguments, like Fortran (I think), but the syntax is entirely different. More commonly it isn't supported, as in my experience, both rdbms environments like Oracle and Sybase, as well as Basic environments (except Liberty) tend to support case only with 'equal' or 'is one of' formulae.

If you need to account for <,>, etc, If/Then/Else is the way to go.

Naith
 

Thanks very much for your responses.

Rosemary's way worked out well.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top