Thursday, July 13, 2006

Adding User-defined Function Libraries to Crystal Reports

Crystal comes with it's own number of Functions that can be used in formula field objects. While crystal provides a huge number of functions that are useful to developers, there are mechanisms to enhance the product with user defined functions libraries. It comes with the ability to accept new functions you develop to meet your needs.

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")
End Function

- Save the project with a meaningful name. Make sure it starts with "CRUFL". For now let's name it as "CRUFLformat"
- Go to --> Make and compile your project into ActiveX DLL (Which will serve as an automation server for Crystal Reports)
- 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

10 comments:

  1. Anonymous3:59 AM

    Oh my goodness! Amazing article dude! Many thanks, However I am encountering problems with
    your RSS. I don't know why I cannot subscribe to it. Is there anybody else having similar RSS issues?
    Anyone that knows the answer can you kindly respond?

    Thanks!!

    Have a look at my homepage drain snake Troon

    ReplyDelete
  2. Anonymous1:06 AM

    fantastic points altogether, you simply woon a logo new reader.
    What may you recommend in regards to yur submit that you made some days ago?
    Any sure?

    Feel free to visit my site ... iron force hack tool

    ReplyDelete
  3. Anonymous7:39 AM

    Consult with an asylum attorney and make sure that you have enough
    time left on your visa status to ensure your stay after being denied.
    Injury attorneys are lawyers that actually work to relieve the stress of the hard
    time by recovering compensation for the injury.

    Our teams of experts go into the depth of the accidents that has happened and find out the real cause and even those who are responsible for the accident.


    Take a look at my homepage: louisville accident lawyer

    ReplyDelete
  4. Anonymous8:40 PM

    Appreciation to my father who told me about this website, this web site
    is truly awesome.

    Here is my blog post ... Long Beach local seo marketing

    ReplyDelete
  5. Anonymous12:20 AM

    Very good post! We will be linking to this particularly great article on our site.
    Keep up the good writing.

    Feel free to surf to my web site :: healthy lawn Offers

    ReplyDelete
  6. Anonymous1:19 AM

    wonderful issues altogether, you just received a new reader.
    What might you suggest in regards to your submit that you simply
    made some days ago? Any sure?

    Also visit my web blog :: diabetes diet

    ReplyDelete
  7. Anonymous11:19 PM

    Hello there! Do you know if they make any plugins to protect against hackers?
    I'm kinda paranoid about losing everything I've worked hard
    on. Any suggestions?

    Look into my web page - after effects optical flares presets

    ReplyDelete
  8. Anonymous12:16 AM

    It is really a nice and useful piece of info. I am satisfied that
    you simply shared this helpful info with us. Please stay
    us up to date like this. Thank you for sharing.


    Here is my web blog :: brooklyn apartments, ,

    ReplyDelete