Share via


Variables (Basic Syntax)

A variable represents a specific data item, or value, and acts as a placeholder for that value. When a formula encounters a variable, the formula searches for the value of the variable and uses it in the formula. Unlike a constant value, which is fixed and unchanging, a variable can be repeatedly assigned different values. You assign a value to a variable and the variable maintains the value until you later assign a new value. Because of this flexibility, it is necessary for you to declare variables before you use them so that Crystal Reports is aware of them and understands how you intend to use them.

This section describes the key components of variables and shows you how to create variables and assign values to them.

If you wanted to report on customers by area code, you could create a variable that extracts the area code from a customer fax number. The following is an example of a variable called areaCode:

Dim areaCode As String
areaCode = Left ({Customer.Fax}, 3)
Rem You could also use: areaCode = {Customer.Fax} (1 To 3)

The first line of the variable example is the variable declaration; it gives the variable a name and type. The database field {Customer.Fax} is a String field and the Left function extracts the first three characters from its current value. The variable areaCode is then assigned this value.

In this section: