Using ranges in formulas

There are twenty-seven functions in Seagate 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.

Rem Compute student letter grades
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. 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


Seagate Software, Inc.
http://www.seagatesoftware.com
Please send comments to:
techpubs@seagatesoftware.com