{"id":89,"date":"2007-12-30T21:28:53","date_gmt":"2007-12-31T04:28:53","guid":{"rendered":"http:\/\/members.crystalreportsbook.com\/crystal-reports-xi\/423-printing-paramter-values\/"},"modified":"2007-12-30T21:28:53","modified_gmt":"2007-12-31T04:28:53","slug":"423-printing-paramter-values","status":"publish","type":"post","link":"http:\/\/www.crystalreportsonlinetraining.com\/training\/423-printing-paramter-values\/","title":{"rendered":"4.23 Printing Paramter Values"},"content":{"rendered":"<h3>Printing Parameter Values<\/h3>\n<p>The second method of using parameters is displaying their value on a report. There are various reasons for displaying parameters on a report. A very common reporting requirement is that when filtering data, it is helpful to print the filter criteria so that anyone reading the report knows that only a subset of all the available data was printed. For example, if a report prints records within a certain date, then you could show the date range within the report header. You can also use a parameter strictly for the purpose of displaying it on the report. For example, printing an invoice could use a parameter to let the user enter a note at the bottom of the invoice to alert the reader of new shipping requirements or tell them about an upcoming price increase.<\/p>\n<p>The way you print the parameter on the report is dependent on the type of parameter it is. Printing a discrete parameter on a report is simple because a parameter is treated the same as any other field. Simply drag and drop it from the Field Explorer onto the report and it will be printed. Printing range and multi-value parameters is more complex because they are represented internally by more than one value. You have to use formulas to tell the report how to display the data. Each parameter type requires a different formula for displaying its information.&#x2; The rest of this section looks at each parameter type and shows you how to print its value on the report.<\/p>\n<p>Range parameters have a start value and end value. Crystal Reports has two functions for working with range parameters: Minimum() and Maximum(). When you pass a range parameter to these two functions, they return the beginning and ending values respectively. Here is an example of using these functions in a formula:<\/p>\n<p>         <code_Single>&#8220;This report covers the dates from &#8221; &amp; Minimum({?DateRange}) &amp; &#8221; to &#8221; &amp; Maximum({?DateRange})<\/code_Single><\/p>\n<p>This formula concatenates the functions Minimum() and Maximum()within a string telling the user the selected date range.<\/p>\n<p>If the parameter is a String data type and can have multiple values, you can use the Join() function to combine them into a single string with a separator. The following code uses the {?Names} parameter to create a comma separated list of user names. Note that the Join() function only works if the parameter is a string data type, not numbers or dates.<\/p>\n<p>         <code_Single>Join({?Names}, &#8220;,&#8221;);<\/code_Single><\/p>\n<p>If you have a more complex parameter that can include multiple values or a range, then more complex programming logic is required. This is because each element in the parameter can have different printing requirements. To print a multi-value parameter, you need to loop through each item in the array and print it out. I built a sample formula for displaying all the multi-value parameter values and separate each one with a comma. This Crystal syntax formula prints the output in a very basic format and you will probably want to modify it to make it specific to your needs.<\/p>\n<p>         <code_Single>NumberVar Index;<\/code_Single><br \/>\n         <code_Single>StringVar Output;<\/code_Single><br \/>\n         <code_Single>StringVar LowerValue; StringVar UpperValue;<\/code_Single><br \/>\n         <code_Single>for Index := 1 to UBound({?Country Range}) Do<\/code_Single><br \/>\n         <code_Single>(<\/code_Single><br \/>\n         <code_Single>\/\/Add a comma to separate values<\/code_Single><br \/>\n         <code_Single>If Output <> &#8220;&#8221; Then<\/code_Single><br \/>\n         <code_Single>Output := Output &amp; &#8220;, &#8220;;<\/code_Single><br \/>\n         <code_Single>LowerValue := &#8220;&#8221;;<\/code_Single><br \/>\n         <code_Single>UpperValue := &#8220;&#8221;;<\/code_Single><br \/>\n         <code_Single>\/\/Get the upper and lower values<\/code_Single><br \/>\n         <code_Single>If HasLowerBound ({?Country Range}[Index]) Then<\/code_Single><br \/>\n         <code_Single>LowerValue := Minimum({?Country Range}[Index]);<\/code_Single><br \/>\n         <code_Single>If HasUpperBound ({?Country Range}[Index]) Then<\/code_Single><br \/>\n         <code_Single>UpperValue := Maximum({?Country Range}[Index]);<\/code_Single><br \/>\n         <code_Single>\/\/Discrete values have the same upper and lower bound<\/code_Single><br \/>\n         <code_Single>If LowerValue = UpperValue Then<\/code_Single><br \/>\n         <code_Single>Output := Output &amp; LowerValue<\/code_Single><br \/>\n         <code_Single>Else<\/code_Single><br \/>\n         <code_Single>\/\/Print the range values<\/code_Single><br \/>\n         <code_Single>(If LowerValue <> &#8220;&#8221; Then<\/code_Single><br \/>\n         <code_Single>Output := Output + &#8221; From &#8221; &amp; LowerValue;<\/code_Single><br \/>\n         <code_Single>If UpperValue <> &#8220;&#8221; Then<\/code_Single><br \/>\n         <code_Single>Output := Output + &#8221; To &#8221; &amp; UpperValue;)<\/code_Single><br \/>\n         <code_Single>);<\/code_Single><br \/>\n         <code_Single>\/\/Clean up the Output string<\/code_Single><br \/>\n         <code_Single>Output := &#8220;The valid values are: &#8221; &amp; Output;<\/code_Single><\/p>\n<p>The formula starts out by declaring the necessary variables. Then it uses a For Loop to cycle through each item in the array. Within the For Loop, it builds the Output string. The first task is to check if the Output string has a value from a previous iteration of the loop and if so append a comma to the end.<\/p>\n<p>The LowerValue and UpperValue variables are populated based upon whether the parameter value has an upper and lower bound. It uses the HasLowerBound() and HasUpperBound() functions to determine this.<\/p>\n<p>Lastly, it concatenates the values to the Output string. If the lower and upper bound values are the same, then this is a discrete parameter value. If they are different, then it is a range parameter value and we want to display the minimum and maximum values.<\/p>\n<p>The For Loop performs this logic for all values in the parameter. An example of the final output is:<\/p>\n<p>         <code_Single>The valid values are: Argentena To Australia, Canada<\/code_Single><\/p>\n<h3>Using Parameters in Formulas<\/h3>\n<p>The third method of using parameters is within formulas. You&#8217;ve already seen examples of this throughout the chapter by modifying the records selection formulas. This can also be used with formulas for conditional formatting or for performing calculations.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Printing Parameter Values The second method of using parameters is displaying their value on a report. There are various reasons for displaying parameters on a report. A very common reporting requirement is that when filtering data, it is helpful to print the filter criteria so that anyone reading the report knows that only a subset [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6,1],"tags":[],"class_list":["post-89","post","type-post","status-publish","format-standard","hentry","category-chapter-4-filtering-data-with-parameters","category-crystal-reports-xi","entry"],"_links":{"self":[{"href":"http:\/\/www.crystalreportsonlinetraining.com\/training\/wp-json\/wp\/v2\/posts\/89","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.crystalreportsonlinetraining.com\/training\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.crystalreportsonlinetraining.com\/training\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.crystalreportsonlinetraining.com\/training\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.crystalreportsonlinetraining.com\/training\/wp-json\/wp\/v2\/comments?post=89"}],"version-history":[{"count":0,"href":"http:\/\/www.crystalreportsonlinetraining.com\/training\/wp-json\/wp\/v2\/posts\/89\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.crystalreportsonlinetraining.com\/training\/wp-json\/wp\/v2\/media?parent=89"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.crystalreportsonlinetraining.com\/training\/wp-json\/wp\/v2\/categories?post=89"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.crystalreportsonlinetraining.com\/training\/wp-json\/wp\/v2\/tags?post=89"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}