• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Chapter 4. Understanding and Implementin... > Crystal Reports in the Real World— C...

Crystal Reports in the Real World— Custom Functions

Some examples of custom functions include handling divide-by-zero errors and handling multilanguage text. Both of these examples are described in this section. A common reason for divide-by-zero errors is simply that a field might not be populated. If a given field has not been populated but it is used in the report, Crystal converts it to a default value. Unless modified, the default value for a numeric field that returns NULL is 0. This means that if there is a formula calculating percent of capacity (Current_Amount/Max_Amount) but the item is new and therefore no max amount has been set, then the Max_Amount field in the database is likely blank. When the preceding formula is applied to the database fields then the result will be an error. Current_Amount/Max_Amount would resolve to some real value divided by NULL, the NULL would be converted to the default value of 0, and the result would be some number divided by 0—and a divide-by-0 error is the result.

To avoid this, create a custom function to handle all division. The custom function simply checks for a denominator of 0 and handles it appropriately.


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint