Working in Crystal Reports can be real messy, especially when it becomes difficult to find the right system defined function to be used. Here is when user -defined functions come to the rescue. User defined functions are called custom functions.
They can be created for:
1.Reports as Report Custom Functions
2.Repository as Repository Custom Functions. These would require a login into the repository.
To create one, when in Crystal Reports XI >>>Click the Formula Workshop Icon on the Experts Toolbar or Click Report >>>Select Formula Workshop ,the Formula Workshop windows appears >>> Right Click on Report Custom Functions located on the top of the tree or the hierarchical view on the top left of the formula experts window as shown below >>> Click New >>>Enter Name of the function >>> Choose from ‘Use Extractor‘ or ‘Use Editor’.
Use Extractor-Use this when you are unsure about the type of arguments you are going to require. Clicking this opens a wizard that contains a list of formulas that could be used as arguments in the Report Custom Functions. They include the formatting formulas also.
Use Editor-Clicking on this will present before you a text editor window that contains all the fields,system functions,grouping functions and most essentially the keywords with their correct syntax. These can be used by double clicking on them.
The ‘( )’ brackets take the arguments.
Note:Don’t enter the function name after the ‘Function’ keyword in the editor.
After you are done writing the code >>> Click on Check (Alt+c) >>> Save and Exit.
As an example I have constructed a report custom function called “Percentage” that calculates percentage.
Function (NumberVar num,NumberVar den) local NumberVar result; result:=num / den; result:=result *100; result
This creates Report Custom Function for your Report.