Crystal Reports Online Training

Learn Online, Anytime, Anywhere

Step-by-step online tutorials.

6.14 Using the Formula Extractor

Using the Formula Extractor

The formula extractor is found within the Formula Workshop. When you create a new custom function you are given the option to use the editor to type it in directly or use the formula extractor. If you click the button Use Formula Extractor, it opens the Formula Extractor dialog box shown in Figure 6-1.



Figure 6-1. The Formula Extractor dialog box.

The Formula window on the left displays the report formulas and formatting formulas. You can select a formula from either list. To select a formula for conversion, you only have to single-click it. The right side of the dialog box automatically changes to show you the internal workings of that formula. At the top is the custom function name and below it is the data type that will be returned. You can change the name if you like, but you can’t change the data type because the formula controls that. Under the Return Type is a summary text box. Type in a description of what the custom function does.

The Arguments window lists each argument that the formula extractor will create. It shows you the field name that it is derived from, the data type, the argument name, and the description. Both the field name and the data type are fixed. You can’t change them because they are derived from the original formula. The Argument Name and the Description can and should be changed. By default, the formula extractor names each argument as v1, v2, v3, etc. This is a meaningless name and should be changed to a name that is more descriptive. The Description is where you can type in a more thorough description of the argument.

At the bottom of the dialog box is the Formula Text window. This tells you how the original formula should be changed so that it calls the custom function. Notice that it also tells you which fields need to be passed to the function and the order that they are passed. In this example, the Ship Date field maps to v1 and the Order Date field maps to v2.

A nice feature is the checkbox below the Formula Text window. By selecting it, the Formula Extractor automatically modifies the formula so that it uses this text that calls the custom function.

When you click the OK button, the new custom function is automatically created and added to the Formula Workshop in two different places. The first place it’s listed is the Report Custom Functions list. This lets you come back to edit the function at a later time. The second place it’s listed is in the Report Functions window with all the other Crystal Report functions. It is shown under the Custom Functions category. This lets you reference it when you are writing report formulas.

If you selected the Modify Formula checkbox, the original formula that this custom function was derived from is modified so that it calls the new custom function and passes the proper fields as arguments.