Chapter 7 - Writing Formulas


Crystal Reports gives you the option to program formulas in either Crystal syntax or Basic syntax. This chapter teaches you how to program with both Basic syntax and Crystal syntax. Dozens of code samples show you exactly how to write code that you can put in your own reports today.

Become a Crystal Reports expert with the authoritative resource available. The tuturials and tips in this book will take your skills to the next level.
Buy at

This is an excerpt from the book Crystal Reports Encyclopedia. Click to read more chapter excerpts.

Crystal Report Data Types

Simple Data Types

Crystal Report's Basic syntax supports the standard typical data types that we expect in a language: Boolean, Number, Currency, String, DateTime, Date, and Time.

Notice that rather than have a large number of numeric data types such as integer, double, etc., there is simply a single data type called Number (Crystal syntax uses NumberVar). There is no need to worry about whether the number is fractional or what its largest value is. One data type handles all cases.

The Currency data type is treated the same as a Number data type with a few exceptions:

  • Currency can only have two decimal places. If assigned a number with more than two decimal places, it rounds up to the nearest penny.
  • Currency automatically gets formatted as a monetary value. This eliminates the overhead of you having to format the variable whenever it gets printed.
  • Since Currency is a different data type, it must be converted to Number to be used in mathematical assignments using non-currency variables. See the section "Converting Data Types' for more information.

Strings use the double quote, ", to specify a string literal. A character is represented by a string of length one. Referencing a position within a string is Base 1. Thus, if you want to refer to the first character in a string, you would use an index of 1. The maximum length of a string constant is 65,534 characters. Information on using the Basic syntax built-in string functions is in Chapter 6.

‘Demonstrate assigning a string constant to a variable

Dim Var As String
Var = "This is a string"

Dates are a little unusual in that there are three different data types available. The Date type can only store a date and the Time type can only store a time. It's preferable to use these data types if you don't need both values stored in a variable. If you do need both types in the same variable, use the DateTime type. Designate a DateTime constant by surrounding it with the # character.

Dim MyBirthday As DateTime
MyBirthday = #5/23/1968#


To read all my books online, click here for the Crystal Reports ebooks.