Using Formulas in Crystal Reports

book list add book to my bookshelf create a bookmark purchase this book online

mastering crystal reports 9
Chapter 4 - Adding Business Logic with the Formula Workshop
Mastering Crystal Reports 9
by Cate McCoy and Gord Maric
Sybex 2003

There are many areas in Crystal that make use of formulas: from retrieving the data to adding calculated values to grouping and sorting creatively right through custom formatting for presentation purposes. The Formula Workshop is a completely new area in Crystal Reports, and its goal is to make writing formulas easy for the novice report designer as well as to address the needs of the veteran formula creators. As we present examples in this chapter, we’ll point out where in Crystal you might use the finished formula and provide some examples to get you coding! We’ll be using some new user interface objects in Crystal Reports 9 as well as some familiar ones from prior releases:

  • The Report Explorer (new in Crystal Reports 9)

  • The Field Explorer

  • The Formula Workshop (new in Crystal Reports 9)

  • The Workshop Tree (new in Crystal Reports 9)

  • The Formula Editor

  • The Formula Expert (new in Crystal Reports 9)

The Report Explorer

The complete structure of a report is available in an abbreviated, easy-to-navigate format using the Report Explorer. The five standard report sections and any additional sections added form leaves on a drill-down tree that can be used to navigate to any part of a report. Formulas are no exception; an entry is made in the Report Explorer showing where report formulas are used. Figure 4.1 shows the Report Explorer in floating format in its own window; it can also be docked to either side of the Crystal development environment (the left side definitely makes more sense because otherwise you obscure the Preview area). The Report Explorer can be opened from the toolbar or by choosing View > Report Explorer.


Figure 4.1. The Report Explorer

In Figure 4.1, the Page Header Tree is expanded and you can see that it contains a box report element, the special field PrintDate, two text objects, and a picture. Group Header #3 is also expanded and shows the use of a formula field in addition to a group and a summary field. Formula fields in Crystal Reports are given names prefixed with an @ symbol; you invent the name, Crystal adds the @ symbol. Using the Report Explorer, you can easily see what is going on in each section right down to where formula fields are being used. Writing code for a formula is done in the Formula Workshop.

There are two ways to open the Formula Workshop in Crystal Reports. The easiest way is to use its toolbar icon. You’ll find this icon on the Expert toolbar with the label X+1. If your Expert toolbar is not displayed, open it by choosing View > Toolbars and enabling its check box.

There is a second formula icon used throughout Crystal Reports that is very similar to the Formula Workshop icon; the second icon has the label X+2. While the X+1 icon opens the complete Formula Workshop, the X+2 icon opens the Format Editor, which is a part of the Formula Workshop. Figure 4.2 shows the Format Editor for a field that contains many opportunities for coding formulas, as is apparent from the X+2 icons.

The Field Explorer

The second path into the Formula Workshop is one that will be familiar to all Crystal Reports 8 and 8.5 users: the Field Explorer. The Field Explorer can be opened from the toolbar or by choosing View > Field Explorer. With the Field Explorer displayed, shown in Figure 4.3, select the Formula Fields category and click the New button near the top of the dialog or right-click to display the submenu and choose New. Pressing Ctrl+N from the keyboard will also work.

After you select New for a new formula field, the dialog shown in Figure 4.4 displays to allow you to name the formula. At this point, Crystal Reports 9 preens a little, showing off its new features. The buttons along the bottom expect you to choose between using the Formula Expert or the Formula Editor. Both choices open the Formula Workshop, albeit with very different screens.

click to expand
Figure 4.2. Using formulas in the Format Editor


Figure 4.3. The Field Explorer


Figure 4.4. Naming a formula

Use of content on this site is expressly subject to the restrictions set forth in the Membership Agreement
 
Conello © 2000-2003     Feedback


Mastering Crystal Reports 9
Mastering Crystal Reports 9
ISBN: 0782141730
EAN: 2147483647
Year: 2005
Pages: 217

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net