Crystal Reports Online Training

Learn Online, Anytime, Anywhere

Step-by-step online tutorials.

B. 2 Data Types and Variables

Simple Data Types

Basic syntax uses the same data types as Crystal syntax. However, the naming convention varies slightly. In Crystal syntax all data type have “Var” at the end (e.g. NumberVar, StringVar, etc.) Basic syntax doesn’t use the “Var” suffix after each data type. It simple uses the data type name by itself: Boolean, Number, Currency, String, DateTime, Date, and Time.

Declaring Variables

To use a variable in a formula, you first have to declare it. This consists of giving it a name and specifying its data type. Declaring a variable follows the format of declaring the variable using the Dim keyword followed by the variable name. Use the As keyword to specify the data type.

Dim var As dataype

Just like Crystal syntax, there are three keywords for setting a variable’s scope (whether other formulas can reference it): Dim, Global, and Shared.

Dim: The variable can only be seen within the current formula. The variable is private to that formula and can’t be used anywhere else in the report. This is the default scope if you don’t specify it.

Global: The variable can be seen within any formula inside the same report. Sub-reports do not have access to the variable.

Shared: Similar to Global, but the variable can also be seen within sub-reports.

Dim HireDate As Date
Shared AffiliateCities() As String

Variable Assignment

In Basic syntax, to assign a value constant to a variable use the equal sign.

X = 5
Y = “Mr. ” & {Customer.Last Name}