Crystal Reports Online Training

Learn Online, Anytime, Anywhere

Step-by-step online tutorials.

7.04 Adding Formulas

Adding Formulas

When modifying a property in the designer, the changes you make to that property stay the same as the report runs. Most properties, but not all, can have a formula attached to them so that their value can be modified based upon other fields in the report. Clicking on the formula button next to a property lets you add a formula to do this. The formula button is shown in Figure 7-4. It has a blue “X-2” and there is a horizontal pencil underneath it. Once you add a formula to a property the “X-2” turns red and the pencil is at an angle. This is shown in Figure 7-5. Only properties with a formula button next to them can use a formula to make the values dynamic.



Figure 7-4. A button with no formula associated with it.


Figure 7-5. A button with a formula associated with it.

When assigning a formula to a property, you have to determine the data type that the property uses. This can be anything from Boolean, string, number, or Crystal pre-defined constants. The formula must return the proper data type to the property. If the formula returns the wrong data type, the Formula Editor returns an error when you try to save it.

As an example of using the proper data type, Figure 7-6 shows the Section Editor dialog box. All the properties displayed here use checkboxes. These properties are either on or off. Formulas that are associated with these properties have to return True or False. As expected, returning True is the same as a checked box, and returning False is the same as an unchecked box.



Figure 7-6. The section expert window.

As a more varied example, Figure 7-7 shows the Border tab of the Format Editor dialog box. This dialog box uses checkboxes, line styles and colors.



Figure 7-7. The Format Editor’s border tab.

The values for the line style and color are predefined constants within Basic syntax. It can have values such as DashedLine, NoLine, etc. The color property can have values such as Aqua, Yellow, etc.

When you open the Formula Editor, the predefined constants for the current property are listed in the Function Tree. This list is dynamic and won’t show predefined constants that don’t apply to the current property. For example, if you are modifying a line style property, the Function Tree will show the different line styles, but won’t list any colors. If you are modifying a color property, it will show the available colors, but no line styles. This is illustrated in Figure 7-8.



Figure 7-8. The Function Tree for line styles.