Crystal Reports Online Training

Learn Online, Anytime, Anywhere

Step-by-step online tutorials.

B. 1 Introducing Basic Syntax

Chapter 7 taught you how to program using Crystal syntax. This appendix builds on that chapter by showing you details of the Basic syntax. It was written as a companion tutorial with Chapter 7 that shows what is unique about Basic syntax compared to Crystal syntax. It doesn’t try to teach you programming all over again. The best way to use this appendix is to read through Chapter 7 first and become familiar with the programming concepts. When you are comfortable, come back to this appendix as a reference for what the differences are with Crystal syntax.

The end of this appendix has conversion tables from Crystal syntax to Basic syntax. The tables list the function names only and you’ll notice that most of them have identical names. There are only a few differences. If you need more information about how the functions work, look at the table headings and flip back to Chapter 7 to see the details.

Basic syntax is very similar (and in many ways identical) to the Basic programming language found on many computers, as well as the Microsoft macro language VBA. If you are already familiar with programming with VBA, then it would be easier for you to learn Basic syntax instead of Crystal syntax.

When creating formulas, if you want to program in Basic syntax you need to be aware that Crystal Reports defaults to using Crystal syntax. To change this, look at the top of the Formula Workshop to find a drop-down box that says Crystal Syntax. Click on it to change it to Basic Syntax (see Figure B-1). After you switch to Basic syntax, you’ll notice that the syntax trees are refreshed so that the functions and operators are specific to the Basic syntax.

Figure B-1. Language Selection

It is very tedious to specify Basic syntax every time you create a new formula. To change the default language to Basic syntax, select the menu options File | Options Formula Editor and select Basic syntax as the default programming language.

Writing Comments

Basic syntax comments are designated with a single apostrophe. All text after the apostrophe is ignored. You can also use the familiar REM keyword.

‘This is a comment
REM This is also a comment

Line Terminators

Basic syntax assumes that each programming statement only takes a single line of text. Hitting the enter key marks the end of the line. If a statement needs more than one line, the line continuation character _ is used.

X = 5 ‘This is a single line
Y = “This takes ” _
& “two lines”

Returning a Value

Formulas return a value by assigning it to the Formula variable. Formulas must always return a value. The following code returns the value True.

Formula = True

If a formula has multiple statements that return a value, all the assignments must be of the same data type. Although there is no way to specifically tell Crystal Reports the data type to return, the compiler will compare all the assignments and check them for consistency. As an example of what not to do, see the following code:

‘The following IS NOT VALID due to the different data types returned and produces an error
If Age > 65 Then
Formula = “Retired”
Else
Formula = Age
End If