Crystalkeen logo; we offer Crystal reports viewers and schedulers
 
Crystalkeen header image 3
Crystalkeen header image 5

Crystal Reports Tools: Improve Performance While Saving Time and Money

  Resources  

Articles:
Administration
Advanced
Basic
Database
Financial

Tools:

Analyzers
CR Schedulers
CR UFLs
CR Viewers
DataBase Tools
Graphics
International
Mail UFLs



 
 

Add'l:
About us

Contact Us
 

CrystalReports
on Steroids

Crystal Reports: Custom Functions

Using 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:
(LastDayPrevMonth).

The custom function in Crystal Syntax will look like: 

Function (DateTimeVar dayInMonth) 
Date (Year (dayInMonth), Month (dayInMonth), 1) – 1 

Then in your report formulas, you can call this custom function for any datefield : 
LastDayPrevMonth({table.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
 

Want more info about functions? Check out this video from Lynda.com:

 

 

 

 

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.

 

  • Questions? Please write to mark@crystalkeen.com. We do want your business.
  • Do you have your own tips for Crystal Reports administrators and designers? Write to mark@crystalkeen.com and we'll post your tips with a link to your Website (or with some other attribution if you choose).
  • Crystal Reports is a subsidiary of Business Objects, which is owned by SAP.