Crystal Reports for Rational Application Developer 设计员指南

使用 If 表达式(Crystal 语法)

If 表达式是 Crystal 语法用途最广泛的功能之一。它还有助于深入了解表达式的本质。将前面的 If 表达式看作单独的公式。注意因为该公式是单个表达式,所以可以不加分号:
If {Orders Detail.Quantity} > 1 Then
"multiple units"
Else
"one unit"
假设想修改该公式,以便打印出“multiple units”或数字 1。
//An erroneous formula
If {Orders Detail.Quantity} > 1 Then
"multiple units"
Else
1
该公式将导致错误。这是因为该表达式中值的类型不同:“Multiple units”是“字符串”值,而 1 是“数字”值。Crystal Reports 要求表达式的值必须始终为单一类型。

注意: 通过使用 CStr 函数将“数字”1 转换为“字符串”值,可以纠正该示例。例如,通过调用 CStr (1, 0),将数字 1 转换为字符串“1”。
//A correct formula
If {Orders Detail.Quantity} > 1 Then
"multiple units"
Else
CStr (1, 0) //Use 0 decimals



Business Objects,SAP 子公司
http://www.china.businessobjects.com/
支持服务
http://www.china.businessobjects.com/support/
Web 上的产品文档
http://support.businessobjects.com/documentation/