#### Using the If expression

The If expression is one of the most widely used features of Crystal syntax. It also provides insight into the nature of expressions. Consider the earlier If expression as a separate formula. Notice that because this formula is a single expression, it does not need a semicolon:

    If {Orders Detail.Quantity} > 1 Then
       "multiple units"
    Else
       "one unit"

Suppose you wanted to modify this formula so that it either prints "multiple units" or the number 1.

    //An erroneous formula
    If {Orders Detail.Quantity} > 1 Then
       "multiple units"
    Else
       1

This formula will result in an error. This is because the values in this expression are different types: "multiple units" is a String value and 1 is a Number value. Seagate Crystal Reports requires that the value of an expression always be of a single type.

Note: This example can be corrected by using the CStr function to convert the Number 1 to a String value. For example, the Number 1 is converted to the string "1" by calling CStr (1, 0).

    //A correct formula
    If {Orders Detail.Quantity} > 1 Then
       "multiple units"
    Else
       CStr (1, 0) //Use 0 decimals

See Control structures for more information on the If expression.

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