Displaying parameter values in your Crystal report

Displaying parameter values in your Crystal reports

 

If your reports include parameters to prompt for user input, you should display the user’s responses on the report so that the user, or the others consuming the report, understands the logic that went into the parameters and, in turn, into the record select query that depends on the parameters.  Here is how to how to handle parameters of various types.

Discrete values

If the user responds to the parameter prompt with a discrete value of any type, you can simply insert the parameter in the report.  This works for Boolean, date, date-time, numeric and string fields.

Range Values

If the parameter requires a range response you must create two formulas to display the high and low values.  Use the minimum and maximum functions to get the starting and ending points of the range respectively.  For example:

//low date
minimum({?hire date})

And

//high date
maximum({?hire date})

Multiple Values

Multiple values present a special challenge. When the user can enter a number of choices, you need to use a loop in order to display all the choices. The following example shows the expression when the user is prompted for a list of states:

numbervar max := count({?state});
numbervar k := 1;
stringvar output := "";
for k := 1 to  max  do

(

output := output +{?state}[k]+","

);

numbervar m := len(output);

left(output,m-1)

 

In the above express {?state} is the parameter field allowing multiple entries. The first line determines the number of entries that the user has provided. The second line creates a counter to be incremented. The third line created a blank output string. The fourth line starts the do loop telling the program to repeat the operation until the number of times equals “max”. The next three lines specify the operation. Each time the do loop is processes the output string is increase by appending another choice plus a comma to the string. The next to the last line calculates the total number of characters in the output string after the loop is done. The last line removes the last comma from the output string.

 

Displaying Boolean Values

 

Often you will include a parameter value with a Boolean value. Crystal will allow you to format the parameter as True and False or Yes and No or 1 and 0 etc.  However it your report will look more professional if you used check boxes, for example:  þ and ¨ .

 

You can display these characters using the Wingdings font and the decimal value associated with each symbol. Use the Windows Character Map program to display all the symbols in Wingdings or any other font. When you hover over the symbol you want the hexadecimal value of the symbol will be displayed.  For example þ has a value of 0FE while ¨ has the value of 0A8. You can use a conversion site such as the one at:

http://www.mathsisfun.com/binary-decimal-hexadecimal-converter.html to convert the hexadecimal values into decimal values. In this case the values are 254 and 168 respectively.

 

You can now use these values in a formula to display the filled and unfilled boxes on your report:

if {?Include Details} then chr(254) else chr(168)

 

Place the formula on your report and format it with Wingdings. The result is nifty check boxes that tell your users when an option has been picked.

 

You can use the same logic to display true and false values in your data.