You write formulas according to a specific set of rules called syntax. Crystal Reports supports both Crystal syntax and Basic syntax. This course will only use Crystal syntax. The Formula Editor checks the syntax and helps identify problems so you can fix them before you add the formula to the report.
Syntax rules are used to create a correct formula. Some of the rules are:
Strings are used to hold text that must be placed between double quotation marks (") or apostrophes (')
Functions may or may not require arguments and/or parentheses
Formulas in the report are identified with a leading @ symbol.
When creating formulas:
- You have the option of using either Crystal syntax or Basic syntax.
- Almost any formula written with one syntax can be written with the other.
- You cannot mix and match Crystal and Basic syntax within a single formula.
- You can have a mix and match of Crystal and Basic syntax formulas within the same report.
If you are already familiar with Crystal syntax, you can continue to use it and benefit from the wide range of functions, operators, and control structures.
If you are familiar with Microsoft Visual Basic or other versions of Basic, then working in the Basic syntax in Crystal Reports may be more comfortable for you. In general, Basic syntax is modeled on Visual Basic except that it has specific extensions to handle reporting.
Report processing is not slowed down by using Basic syntax. Reports using Basic syntax formulas can run on any machine that Crystal Reports runs on. Also, using Basic syntax formulas does not require distributing any additional files with your reports.
Changing the syntax from Crystal syntax to Basic syntax or going from Basic syntax to Crystal syntax changes the list of functions in the Functions window as well as the list of operators in the Operators window. However, the available report fields remain the same since the report fields are available to both syntax.
Special Characters Used in Crystal Syntax
The following table displays the special characters used in Crystal syntax:
Special Characters used in Crystal Syntax
|Denotes that everything following is a comment and is ignored by the //Formula Editor. You must repeat the // for each line that you want to comment out.
|Denotes the arguments that follow a function. Many functions require more than one argument separated by a comma within the parentheses (also known as round brackets). They can also denote precedence, forcing parts of your formula between the ( ) to evaluate first.
|Denotes fields. All types of fields, such as database, other formulas, and special, are enclosed in braces (also known as French braces or curly brackets).
|Denotes subscripts or arrays. Brackets (also known as square brackets) before a function denote [ ] an array, whereas brackets after a function indicate a subscript (returns specific characters from a string).
|Denotes literals. Any text between the quotes is printed as it appears between the quotes. This functionality is useful when you want punctuation, text, or special characters to appear as part of the result. Single quotation marks (' ') can also be used for this purpose.
|Upper or lower case is ignored by the Formula Editor. You can enter your functions in all caps, all lower, or any mix you prefer.
|Carriage returns are ignored in the Formula Editor. You can have line breaks and blank lines almost anywhere in the formula.