Formulas are used in Crystal Reports as a way to have enhanced control over a report as it prints. For example, if you want to have the rows on the report alternate colors then you can use a formula to change the background color of every other row. Another example would be using a field value in a row to determine when to hide a row.
Crystal Reports gives you the option to program formulas in either Crystal syntax or Basic syntax. This chapter teaches you how to program with Basic syntax. Even though the focus of this chapter is Basic syntax, the differences between Crystal syntax and Basic syntax are noted when necessary.
Basic syntax is very similar (and in many ways identical) to the VB .NET syntax. Crystal syntax is similar to the C# syntax. If you are a C# programmer you will probably be more comfortable programming with Crystal syntax.
When creating formulas, Crystal Reports defaults to Crystal syntax so you need to select Basic syntax. It is very tedious to specify Basic syntax every time you create a new formula. To change the default language to Basic syntax, right click on the report in design mode and select Designer | Default Settings. Go to the Reporting tab and at the bottom you can specify Basic syntax as the default language.
After you switch to Basic syntax you’ll notice that the syntax trees are refreshed so that they reflect the language you chose. Figure 8-1 shows how to choose Basic syntax from the Formula Editor.
Figure 8-1. Language Selection
Since Basic syntax is so similar to VB .NET, this chapter gives an overview of the language and focuses on the areas where they are different. I assume that since you are already programming with Visual Studio .NET then you don’t want to be bored with elementary programming concepts. Throughout this chapter, Basic syntax will be compared to VB .NET syntax to bring noteworthy differences to your attention. Detailed examples will be shown when it is deemed to be helpful.