Share via


Range Data Types (Basic Syntax)

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_, Is >, Is >=, Is < and Is <= keywords. In general, To is used for ranges with two endpoints, and Is is 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

Is <= 5

All number less than 5

Is < 5

Examples of DateTime Range values

#Jan 5, 1999# To #Dec 12, 2000#
Is >= #Jan 1, 2000#

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 statements. 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 Case {Student.Test Scores}
   Case Is >= 90
      formula = "A"
   Case 80 To_ 90
      formula = "B"
   Case 70 To_ 80
      formula = "C"
   Case 60 To_ 70
      formula = "D"
   Case Else
      formula = "F"
End Select

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

formula = 5 In 2 To 10 'True
formula = 5 In 2 To_ 5 'False
formula = 5 In 2 To 5 'True

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

formula = Maximum (2 To 10) 'Returns 10