Both available syntaxes (Crystal syntax and Basic syntax) have a branch with additional functions on the bottom of the middle tree. User-defined functions can be added to the additional functions branch of the tree just like if they were existing crystal reports functions.
Creating a user-defined function library
There are two types of function libraries supported by Crystal. Dynamic link libraries and COM Automation server. These libraries can be written in several languages. Dynamic link libraries are usually written in C and must include those files shipped with Crystal. you can also download these files from Crystal Decisions support site.
How to create a project to write functions?
It's really simple and you don't need to worry about interface definitions. Let's write a small function using Visual Basic.
- Create a ActiveX DLL project in Visual Basic
- Add a function named "DateFormat" to your class module or copy the following code.
Public Function DateFormat(ByVal sDate As String) As String
DateFormat = Format(sDate, "dd/MMM/yyyy")
- Save the project with a meaningful name. Make sure it starts with "CRUFL". For now let's name it as "CRUFLformat"
- Go to
- Copy the CRUFLformat.DLL into a directory(better if Windows or crystal reports directory) and register it using regsvr32 exe.
Using it in Crystal Reports
- Create a new report using a database you prefer.
- Insert a formula field. Formula window must appear with 3 panes.
- In the middle pane, go to the Additional functions branch andd you'll see DateFormat function. use it to format the date in a date field.
- Edit the function (changing the date format) and see the difference