Additional Functions You Can Add To Crystal Reports
Additional Functions You Can Add To Crystal Reports
Overview
This document is intended for report designers and developers who wish to add
additional functions to the Crystal Reports Formula Editor. It lists and describes
all the supported Additional User Functions contained in various UFL files
available on the Crystal Reports CD and/or website, and provides instructions
for locating and installing these additional functions.
To navigate this document more easily, display the document map in Word: on
the View menu, click Document Map.
This displays a collapsible tree at left, which you can use to jump directly to a
section within the document.
Contents
INTRODUCTION - WHAT ARE UFLS? ............................................................. 3
Using this document.....................................................................................3
Where do you obtain UFL files? ..................................................................3
To download the EXE from our web site........................................................... 4
To obtain a UFL from the Crystal Reports CD .................................................. 4
Working with UFLs......................................................................................4
To add an additional function ............................................................................ 4
FUNCTIONS LISTED BY TYPE......................................................................... 5
Date or Time functions.................................................................................5
21st Century Date UFL...................................................................................... 5
Btrieve Time UFL ........................................................................................6
Day of Year, Week of Year ...........................................................................7
Date Time Difference UFL ..........................................................................7
Date Add UFL..............................................................................................8
Julian to Date UFL ......................................................................................9
Paradox Time UFL ......................................................................................9
Seconds Since Midnight UFL.....................................................................10
Number to Date UFL .................................................................................11
String functions ..........................................................................................12
Title Caps UFL ..........................................................................................12
Search and Replace UFL ...........................................................................13
String Token UFL ......................................................................................13
7/9/2003 3:48 PM Copyright 2002 Crystal Decisions, Inc. All Rights Reserved. Page 1
Crystal Reports Additional Functions you can add to Crystal Reports
7/9/2003 3:48 PM Copyright 2002 Crystal Decisions, Inc. All Rights Reserved. Page 2
cr_ufls.pdf
Crystal Reports Additional Functions you can add to Crystal Reports
Additional UFLs are not included when you install Crystal Reports. You need
to install them separately. Once you have installed the necessary UFL file you
will see the new function(s) in the Additional Functions folder of the Crystal
Reports Formula Editor.
• Files starting with “UFL” are for use with any 16-bit version of Crystal
Reports
• Files starting with “U2L” are for use with any 32-bit version of Crystal
Reports
• Files starting with “UF5” are for use with 16-bit 5.0.x.108 and higher
• Files starting with “U25” are for use with 32-bit 5.0.x.108 and higher
NOTE Although there are four different naming conventions used by User Function Libraries,
throughout this document they will all be referred to as “UFLs”.
A single UFL file (Uflname.dll) may contain more than one function. Once
installed, a UFL’s additional functions will display automatically in the formula
editor the next time you start Crystal Reports, just like regular functions.
7/9/2003 3:48 PM Copyright 2002 Crystal Decisions, Inc. All Rights Reserved. Page 3
cr_ufls.pdf
Crystal Reports Additional Functions you can add to Crystal Reports
You can also find installation instructions in the Readme.txt or Install.txt file
included with the EXE.
7/9/2003 3:48 PM Copyright 2002 Crystal Decisions, Inc. All Rights Reserved. Page 4
cr_ufls.pdf
Crystal Reports Additional Functions you can add to Crystal Reports
7/9/2003 3:48 PM Copyright 2002 Crystal Decisions, Inc. All Rights Reserved. Page 5
cr_ufls.pdf
Crystal Reports Additional Functions you can add to Crystal Reports
DateTimeTo2000(x,y)
This function will convert a DATE/TIME field "x" to a date in the 21st century
IF the last 2 digits of the year are LESS than the number "y".
DTSTo2000(x,y)
This function will convert a DATE/TIME STRING field "x" to a date in the 21st
century IF the last 2 digits of the year are LESS than the number "y".
Examples
{DateField} is a Date field in the database with a 2-digit year of 48. {DateTime}
is a Date/Time field in the database with a 2-digit year of 47. {DTS} is a
Date/Time String field in the database with a 2-digit year of 46.
Examples
Where {numberfield} is a NUMERIC decimal field representing a fraction of a
day between 0 and 1.
7/9/2003 3:48 PM Copyright 2002 Crystal Decisions, Inc. All Rights Reserved. Page 6
cr_ufls.pdf
Crystal Reports Additional Functions you can add to Crystal Reports
Formula Syntax
DayOfYear({datefield})
WeekOfYear({datefield})
Examples
DayOfYear(Date(1998,01,25)) Returns 25.00
WeekOfYear(Date(1998,01,25)) Returns 5.00 (Sunday is 1st day of
week)
7/9/2003 3:48 PM Copyright 2002 Crystal Decisions, Inc. All Rights Reserved. Page 7
cr_ufls.pdf
Crystal Reports Additional Functions you can add to Crystal Reports
Arguments Description
Interval Required. String expression that is the interval of time you
want to add.
Number Required. Numeric expression that is the number of intervals
you want to add. It can be positive (to get dates in the future)
or negative (to get dates in the past).
Date Required. Variant (Date) or literal representing date to which
the interval is added.
Interval Description
Setting
yyyy Year
q Quarter
m Month
Y Day of year
d Day
w Weekday (same as Day)
ww Week
h Hour
n Minute
s Second
Formula Syntax
DateAdd ("m",1 ,DateTime(2000,1,31,1,2,3))
Returns:
7/9/2003 3:48 PM Copyright 2002 Crystal Decisions, Inc. All Rights Reserved. Page 8
cr_ufls.pdf
Crystal Reports Additional Functions you can add to Crystal Reports
Filename UFLJUL.EXE
Compatible with versions: 4.0 and higher
Description Adds new functions to allow conversion to and from Julian
Date fields.
32-bit DLL U2LJUL.DLL
16-bit DLL UFLJUL.DLL
Adds DateToJulian(x)
functions JulianToDate(x)
Formula Syntax
DateToJulian (date) Takes a date field and returns the Julian date value.
JulianToDate (number) Takes a Julian date and returns the date value.
Examples
DateToJulian (date(1995,12,25))
Would convert 12/25/1995 to 2450077 (the Julian date)
JulianToDate ({table.datefield})
Would convert 2450077 (the Julian date) to a 12/25/1995.
Some date fields use a special julian-type date format that is based on a
particular date, for example January 1, 1900. The following formulas would
convert them:
DateToJulian(<date>) - DateToJulian(Date(1900,1,1)-1)
//1 is subtracted from the special date 'start time'
//so the start date is included when calculating the
//difference.
To convert a special Julian date field to normal date:
JulianToDate( DateToJulian(Date(1900,01,01)-1) +
{table.date} )
7/9/2003 3:48 PM Copyright 2002 Crystal Decisions, Inc. All Rights Reserved. Page 9
cr_ufls.pdf
Crystal Reports Additional Functions you can add to Crystal Reports
However, this new UFL does the conversion automatically, and converts the
field into Crystal Reports Time format, which allows more flexibility in
formatting, and includes support for the Microsoft Windows Time-format
settings.
Formula Syntax
PDXTimeToCRTime({table.timefield})
Examples
PDXTimeToCRTime({table.timefield})
Returns the time in HH:MM:SS AM/PM format (Crystal Reports Time format)
If you are going to do calculations with the Paradox Time fields (such as Time
minus Time), you will probably want to do those calculations with the original
fields since it is easier to do the calculations with numeric Seconds. When you
are done your calculations and are ready to display the result in formatted
fashion, just place the result in the PDXTimeToCRTime() function.
NOTE Attempting to pass the PDXTimeToCRTime() function a number that is out of range (less
than zero, or greater than 86399) will generate an error in the Formula Editor.
MinutesFromSecsSinceMidnight ({Table.Time})
- returns the minutes since midnight as an number.
SecondsFromSecsSinceMidnight ({Table.Time})
- returns the seconds since midnight as an number.
HHMMPMFromSecsSinceMidnight({Table.Time})
- returns the time as a string in the format HH:MM PM
HHMMSSPMFromSecsSinceMidnight({Table.Time})
- returns the time as a string in the format HH:MM:SS PM
HHMMFromSecsSinceMidnight({Table.Time})
- returns the time as a string in a military time format HH:MM
7/9/2003 3:48 PM Copyright 2002 Crystal Decisions, Inc. All Rights Reserved. Page 10
cr_ufls.pdf
Crystal Reports Additional Functions you can add to Crystal Reports
HHMMSSFromSecsSinceMidnight({Table.Time})
- returns the time as a string in a military time format
HH:MM:SS
CRTimeFromSecsSinceMidnight({Table.Time})
- returns a Crystal Reports Time field for 5.0
WeekOfYear({Table.Datefield})
- Returns the Week of the Year as a Number, much like the
Day Of Week Function
NOTE These UFLs could be made compatible with Crystal Reports 4.x if the function
"CRTimeFromSecsSinceMidnight({Table.Time})" was left out, since it uses a Crystal
Reports Time type that was not available with Crystal Reports 4.x versions.
While you can sometimes use numbers in the format YYMMDD, they cannot be
formatted in CR with a long year.
For example,
NumberToDate(991030)
returns Date(1999,10,30). Often, the default displays format on the report for
dates is MM/DD/YY, so this formula returns 10/30/99.
However, if you format this formula field to display in MMM DD, YYYY
format, this formula returns October 30, 99.
7/9/2003 3:48 PM Copyright 2002 Crystal Decisions, Inc. All Rights Reserved. Page 11
cr_ufls.pdf
Crystal Reports Additional Functions you can add to Crystal Reports
The solution? Use a 4-digit number for year with the NumberToDate function.
String functions
This sections describes additional functions to:
Examples
LeadingCaps("tHiS IS THE uflcaps-conVERTed strinG.")
This returns the string: "This Is The Uflcaps-Converted String."
Notice that letters following a space, tab or hyphen character are capitalized.
7/9/2003 3:48 PM Copyright 2002 Crystal Decisions, Inc. All Rights Reserved. Page 12
cr_ufls.pdf
Crystal Reports Additional Functions you can add to Crystal Reports
Examples
SearchAndReplace ("This is my dog.", "DOG", "CAT", False)
Returns the string "This is my CAT."
NOTE The “searchandreplace” function in version 8 and 8.5 does not need to be used this is
because the “replace” function provides this functionality.
Formula Syntax
StrTok (x, y, z)
Where "x" is the string you are parsing, "y" is your separator that is between
each token and "z" is the numeric representing which "token" you want to
return.
7/9/2003 3:48 PM Copyright 2002 Crystal Decisions, Inc. All Rights Reserved. Page 13
cr_ufls.pdf
Crystal Reports Additional Functions you can add to Crystal Reports
Examples
{string1} = "first.second.third.fourth"
StrTok ({string1}, ".", 0)
Returns Error message stating system is begins with ‘1’
NOTE This function requires that you KNOW how many "tokens" are in the string you are
parsing. Otherwise, your formula will return the errors listed above.
7/9/2003 3:48 PM Copyright 2002 Crystal Decisions, Inc. All Rights Reserved. Page 14
cr_ufls.pdf
Crystal Reports Additional Functions you can add to Crystal Reports
StringBeforeChar("Tummonds*Fred","*")
Returns the STRING "Tummonds"
StringAfterChar("Tummonds*Fred","*")
Returns the STRING "Fred"
7/9/2003 3:48 PM Copyright 2002 Crystal Decisions, Inc. All Rights Reserved. Page 15
cr_ufls.pdf
Crystal Reports Additional Functions you can add to Crystal Reports
Examples
SquareRoot (16)
Returns 4.00
SquareRoot (73)
Returns 8.54
SquareRoot (-8)
Returns Error
Mathematical functions
This section describes additional functions to:
Exponent UFL
Filename UFLEXPO.EXE
Compatible with versions: 4.0 and higher
Description Adds new functions allowing you to return exponential
numbers and numbers in scientific format.
32-bit DLL U2LEXPO.DLL
16-bit DLL UFLEXPO.DLL
Adds EXPO(x,y)
functions ScNotn(x,y)
7/9/2003 3:48 PM Copyright 2002 Crystal Decisions, Inc. All Rights Reserved. Page 16
cr_ufls.pdf
Crystal Reports Additional Functions you can add to Crystal Reports
Formula Syntax
EXPO(x,y) Will return a number of "x" to the power of "y"
ScNotn(x,y) Will return a string of "x" in scientific notation with
"y"-1 significant digits.
Examples
EXPO(2,4) Returns 16.0
ScNotn(2,4) Returns 2.000E+00
Math UFL
Filename UflMath.exe
Compatible with versions: 7.0 32-bit
Description User Function Library (UFL) containing several math
conversion functions including Hexadecimal digits, fractions,
logarithms, and Trigonometric functions. These functions can
be used to extend the Crystal Reports formula language.
32-bit DLL CRUFLMath.dll
16-bit DLL **Only available in 32-bit**
Adds NumberToHex (Number)
functions HexToNumber (Hex)
BinaryToNumber (Binary)
NumberToFraction (Number)
NumberToLog (Number)
Sine (Number)
Cosine (Number)
Tangent (Number)
Arctangent (Number)
Installation
To include these functions into the Additional Functions Section of the Crystal
Formula Editor:
7/9/2003 3:48 PM Copyright 2002 Crystal Decisions, Inc. All Rights Reserved. Page 17
cr_ufls.pdf
Crystal Reports Additional Functions you can add to Crystal Reports
Formula Syntax
NumberToHex (Number) returns a Hex String.
Examples
SquareRoot(16) Returns 4.00
7/9/2003 3:48 PM Copyright 2002 Crystal Decisions, Inc. All Rights Reserved. Page 18
cr_ufls.pdf
Crystal Reports Additional Functions you can add to Crystal Reports
Other
This sections describes additional functions to:
@MultiLines
"This is line one." + CHR(13) + "This is line two."
returns two lines:
7/9/2003 3:48 PM Copyright 2002 Crystal Decisions, Inc. All Rights Reserved. Page 19
cr_ufls.pdf
Crystal Reports Additional Functions you can add to Crystal Reports
13 is the ASCII code for ‘carriage return’, so inserting a CHR(13) between two
strings ensures each string prints on separate line.
NOTE The above functions work for ASCII codes 1 - 255 based on the Window ASCII character
set which is different than the DOS ASCII character set.
Formula Syntax
StrANSI2OEM (x) This will convert an ANSI string "x" to an OEM string
StrOEM2ANSI (x) This will convert an OEM string "x" to an ANSI string
7/9/2003 3:48 PM Copyright 2002 Crystal Decisions, Inc. All Rights Reserved. Page 20
cr_ufls.pdf
Crystal Reports Additional Functions you can add to Crystal Reports
Installation:
To include these functions into the Additional Functions Section of the Crystal
Formula Editor:
Formula Syntax
CentimetersToInches (Centimeters) converts a number representing
centimeters to a number representing inches.
7/9/2003 3:48 PM Copyright 2002 Crystal Decisions, Inc. All Rights Reserved. Page 21
cr_ufls.pdf
Crystal Reports Additional Functions you can add to Crystal Reports
UFL Template
Filename UFLSKEL.EXE
Compatible with versions: 4.0 and higher of the Professional
version only
Description This is a sample DLL and code to show the basic method of
creating your own UFL function DLL's with C++. Includes
sample C++ code to create 16 and 32-bit DLLs.
32-bit DLL U2LSKEL.DLL
16-bit DLL UFLSKEL.DLL
Adds Design Your Own!
functions
Formula Syntax
You Decide!
Examples
You Decide!
For more information on creating your own UFLs, search under ‘Creating User
Defined Functions…” in the index of Crystal Reports online Developer’s Help.
7/9/2003 3:48 PM Copyright 2002 Crystal Decisions, Inc. All Rights Reserved. Page 22
cr_ufls.pdf
Crystal Reports Additional Functions you can add to Crystal Reports
Practical uses for UFLSTORE are numerous and most of them relate to
subreports. If you have created a subreport and would like to use the
information that it generates in the main report, then UFLSTORE is the way to
do it. The exciting thing is that the information stored is available not only to
the main report but to all subreports contained with in it. A few ideas from Tech
Support:
• Create a Grand Total that adds all totals from the subreport and main report.
This is a good way for combining totals that come from non-related
databases.
• Create an index for your main report. With a good working knowledge of
your database you could create an index that will tell the user which page
certain information (groups, totals etc) is printed on.
Formula Syntax
@Store Formula
The first step is to place the information into the memory variable by using the
store function that matches the type of information being stored.
7/9/2003 3:48 PM Copyright 2002 Crystal Decisions, Inc. All Rights Reserved. Page 23
cr_ufls.pdf
Crystal Reports Additional Functions you can add to Crystal Reports
@Fetch Formula
The second step is to retrieve the information using the corresponding fetch
function and variable name
@Store Example
StoreNumberVar("SubreportTotal",1000)
This formula stores the variable called ‘SubreportTotal’ with a value of 1000
into memory.
@Fetch Example
FetchNumberVar("SubreportTotal")
This formula fetches the variable created in the @Store formula, and returns the
value that was assigned to the variable in the @Store formula.
To ensure the @Fetch formula successfully retrieves the variable declared &
assigned a value in the @Store formula, you must place @Fetch in a section
beneath the section containing @Store.
NOTE For more information about using Store and Fetch functions, please go to
http://support.crystaldecisions.com/docs and search for the file Uflstore.pdf (the Store and
Fetch Functions technical brief).
Examples
StoreNumberVar(X, Y)
Usage: Stores a numeric value Y to X. If a formula field contains this
function, it will return the numeric value Y.
Returns: 1000
StoreStringVar(X, Y)
Usage: Stores a string value Y to key X. If a formula field just contains this
function, it will return a string value Y.
7/9/2003 3:48 PM Copyright 2002 Crystal Decisions, Inc. All Rights Reserved. Page 24
cr_ufls.pdf
Crystal Reports Additional Functions you can add to Crystal Reports
Returns: Beanie
StoreDateVar(X, Y)
Usage: Stores a date value Y to key X. If a formula field just contains this
function, it will return a date value Y.
StoreCurrencyVar(X, Y)
Usage: Stores a string value Y to key X. If a formula field just contains this
function, it will return a string value Y. This is same as using
SaveNumberVar().
Returns: $1,000.00
StoreBooleanVar(X, Y)
Usage: Stores a True/False value Y to key X. If a formula field just contains
this function, it will return a string value Y.
Returns: True
FetchNumberVar(X)
Usage: Given the key X, it will return a numeric value that is stored under this
key.
Example: FetchNumberVar("gTotal")
Returns: 1000
FetchStringVar(X)
Usage: Given the key X, it will return a string value that is stored under this
key.
Returns: Beanie
FetchDateVar(X)
Usage: Given the key X, it will return a date value that is stored under this key.
Example: FetchDateVar("MyBDate")
7/9/2003 3:48 PM Copyright 2002 Crystal Decisions, Inc. All Rights Reserved. Page 25
cr_ufls.pdf
Crystal Reports Additional Functions you can add to Crystal Reports
FetchCurrencyVar(X)
Usage: Given the key X, it will return a currency value that is stored under this
key.
Example: FetchCurrencyVar("gTotal")
Returns: $1,000.00
FetchBooleanVar(X)
Usage: Given the key X, it will return a Boolean value that is stored under this
key.
Returns: True
Self-serve Support:
http://support.crystaldecisions.com/
Email Support:
http://support.crystaldecisions.com/support/answers.asp
Telephone Support:
http://www.crystaldecisions.com/contact/support.asp
7/9/2003 3:48 PM Copyright 2002 Crystal Decisions, Inc. All Rights Reserved. Page 26
cr_ufls.pdf
Crystal Reports Additional Functions you can add to Crystal Reports
Function Filename
A
7/9/2003 3:48 PM Copyright 2002 Crystal Decisions, Inc. All Rights Reserved. Page 27
cr_ufls.pdf
Crystal Reports Additional Functions you can add to Crystal Reports
7/9/2003 3:48 PM Copyright 2002 Crystal Decisions, Inc. All Rights Reserved. Page 28
cr_ufls.pdf
Crystal Reports Additional Functions you can add to Crystal Reports
7/9/2003 3:48 PM Copyright 2002 Crystal Decisions, Inc. All Rights Reserved. Page 29
cr_ufls.pdf