|
|||||||||
|
|
![]() |
|
|
|
![]() |
<
![]() |
|
Crystal Reports Tools: Improve Performance While Saving Time and Money |
|
Crystal Reports: Custom FunctionsUsing Crystal Reports 9 Custom Functions Custom functions enable you to create a general function and use this in several formulas in your report. In this example we need to develop a custom function to calculate the last day of the previous month for the date we pass as an argument to the custom function. In the formula workshop, select “New/Custom Function” and give your custom function a name: The custom function in Crystal Syntax will look like:
Then in your report formulas, you can call this custom function for any datefield : Custom functions cannot use shared or global variables, or database fields, although you can pass these into the custom function as arguments to the function. You cannot use Print State, Document Properties, User Function Library and some internal functions like Rnd, CurrentFieldValue, DefaultAttribute or GridRowColumnValue. This raises the interesting point that while you cannot use “PrintDate” you can use: “CurrentDate” in the calculations inside your function. Custom Functions can return an array or range. You can leave your custom function in your report, or save it to the repository and use it in several reports.
In November 2001, we published Charliy Nash’s excellent formula for accurately calculating a person’s age as at any date. Charliy has now sent us the formula as a Custom Function. Place this in the repository to have the function available in all your Crystal reports: Function (datetimevar Birth,
datetimevar Current) if Month(Birth) < Month(Current) or (Month(Birth) =
Month(Current) and Day(Birth) <= Day(Current)) then year(Current) -
year(Birth) else year(Current) - year(Birth) – 1
This article is copyrighted by Crystalkeen, Mindconnection, and Chelsea Technologies Ltd. It may be freely copied and distributed as long as the original copyright is displayed and no modifications are made to this material. Extracts are permitted. The names Crystal Reports and Seagate Info are trademarks owned by Business Objects. |
|
|