This documentation is archived and is not being maintained.

# Range Data Types (Crystal Syntax)

Visual Studio 2005

Ranges are designed to handle a spectrum of values. Range types are available for all the simple types except for Boolean. That is: Number Range, Currency Range, String Range, Date Range, Time Range and DateTime Range. You can generate ranges using the To, _To, To_, _To_, UpTo, UpTo_, UpFrom, and UpFrom_ keywords. In general, To is used for ranges with two endpoints, and UpTo and UpFrom are used for open ended ranges (only one endpoint). The underscores are used to indicate whether or not the endpoints are in the range.

Examples of Number Range values

The range of numbers from 2 to 5 including both 2 and 5

2 To 5

The range of numbers from 2 to 5, not including 2 but including 5

2 _To 5

All numbers less than or equal to 5

UpTo 5

All number less than 5

UpTo_ 5

Examples of DateTime Range values:

#Jan 5, 1999# To #Dec 12, 2000#
UpFrom #Jan 1, 2000#

## Using Ranges in Formulas

There are twenty-seven functions in Crystal Reports that specify date ranges. For example, the function LastFullMonth specifies a range of date values that includes all dates from the first to last day of the previous month. So if today's date is September 15, 1999 then LastFullMonth is the same as the range value CDate (#Aug 1, 1999#) To CDate (#Aug 31, 1999#).

Ranges are often used with If or Select expressions. The following example computes student letter grades based on their test scores. Scores greater than or equal to 90 receive an "A", scores from 80 to 90, not including 90, receive a "B" and so on.

Select {Student.Test Scores}
Case UpFrom 90 :
"A"
Case 80 To_ 90 :
"B"
Case 70 To_ 80 :
"C"
Case 60 To_ 70 :
"D"
Default :
"F";

The above example uses the Select expression which is discussed in more detail in Control Structures (Crystal Syntax). You can check if a value is in a range by using the In operator. For example:

5 In 2 To 10; //True
5 In 2 To_ 5; //False
5 In 2 To 5; //True

The Maximum and Minimum functions can be used to find the endpoints of a range:

Maximum (2 To 10) //Returns 10