Crystal Reports Online Training

Learn Online, Anytime, Anywhere

Step-by-step online tutorials.

5.08 Working with Programming Code

Working with Programming Code


These three buttons assist you with programming specific tasks. The first button tells Crystal Reports whether you are programming with Crystal syntax or Basic syntax. We’ll discuss programming languages in more detail in the next two chapters. For now you just need to know that this button lets you choose the language you want to program with.

Record selection formulas must be written in Crystal Syntax. Crystal Reports tries to convert every record selection formula into an SQL expression so that it can make the database do the work of filtering the data. It can only do this if the formula is written in Crystal syntax. Thus, switching to Basic syntax is not option in the Formula Workshop when writing record selection formulas.

Most people always program in the same language. By default, Crystal Reports is set to use Crystal syntax as the programming language. If you prefer to program with Basic syntax then you should change the default programming language. To do this, select the menu items File > Options > Formula Editor. Near the bottom of the dialog box is a dropdown box that lets you choose the default language. Click on it and select Basic syntax.

The Exceptions for Nulls button determines how to handle null values in your data. Normally, when a field in a formula has a Null value, the formula generates an error or returns an invalid result. To get around this you should test for Nulls within your code. But another option is to set this button to Default Values For Nulls. This tells Crystal Reports to replace Null values with the default value for each field type (e.g. Numbers are 0, Strings are the empty string, etc.). This keeps your code cleaner because you don’t have to write extra error checking.

The last button is the Comment/Uncomment button. It’s pretty slick because it lets you comment out a bunch of code with the click of a button. If you have a section of code that you want to temporarily remove because it is causing errors, use the mouse to highlight the lines of code and then click on this button. Crystal Reports automatically makes each line a comment by inserting the comment character at the beginning of the line. If you later want to use the code again, highlight the same lines and click the button again. It removes the comment character so that the lines become active again.