Shows the code required to create a For loop and then a selection statement using Crystal's CASE code. This code can be modified for a wide variety of situations. In this case the report's subject is not important since this is intended as an example of how to set up the code. Nevertheless, this report is set up to return 6 different queries depending on the option selected in the Print Options panel from Cyrious. For example, one option would return all orders where a request for floor plans has been sent but not returned, etc.

Count the number of variables which are found to be checked and print a message based on how many found. Crystal's For loop functions very much the same as in Cyrious's cfl_ch_3-formulas_and_functions with the exception that you do not need to include the ENDFOR command; however the syntax for the CASE statement is quite different. Begin with “SELECT” and then the variable you are comparing. For each comparison begin with “Case” following by the value you are anticipating or comparing, followed by a “:” and then the action you want to take place if there is a match.

Note also from this example that temporary and global variables use a different syntax than Cyrious. Note that the variable type is specified in the declaration. So this example may be a useful shortcut figuring out the code for an application you are writing.


  1. Right click on Formula fields and select New. Name your variable.
  2. Enter the following code in the formula code panel. The CHR(13) designates a “hard return” so that you will get two lines instead of a single line. In cfl_ch_3-formulas_and_functions this would be CHAR(13).
//Returns the number of options (parameters) selected for the search criteria
//Creates error message to select only one option if more than one selected
local numbervar counter;
local numbervar numberofselections :=0;
For Counter := 1 to 6 DO
  Select Counter
   Case 1 : If {?Flr Plans Requested_Not Returned} Then numberofselections := numberofselections +1
   Case 2 : If {?Flr Plans Requested and Rcvd} Then numberofselections := numberofselections +1
   Case 3 : If {?Submittals Sent Not Returned} Then numberofselections := numberofselections +1
   Case 4 : If {?Submittals Needing Revision} Then numberofselections := numberofselections +1
   Case 5 : If {?Rev Subs Rcvd-Production Approved} Then numberofselections := numberofselections +1
   Case 6 : If {?Rev Subs Sent Not Returned} Then numberofselections := numberofselections +1
Default: numberofselections := numberofselections;
IF numberofselections > 1 
  THEN "You Have " + TOTEXT(numberofselections,0) + " Seach Options Specified" 
  + CHR(13) + "Please Select Only One Option"
  1. The following Screen Shot shows the result produced by this code if 3 search options are checked. To have the line print in Red, we have used Crystal's “Format Field” Command [left click on the formula] to change the Font to Red. We could have used the Format Field Suppress Command to suppress the field if the Formula is Null; but since the result is null if there is not an error, this is unnecessary. Nothing will be printed at all if the code returns a 0 or a 1 in its loop through the possible Parameters available on the Options menu.

Contributor: Steve Gillispie, Acorn Sign Graphics

Date: 04/1/2010

Version: Control 04.40.1003.3102

You could leave a comment if you were logged in.