Crystal Reports for Rational Application Developer 设计员指南

求值时间

公式并不是“根据需要”求值或者调用的(即,一个公式无法调用另一个公式来执行某些处理,即使是使用全局变量)。
例如:
Rem Formula PrintSquare
Global x As Number
x = 5
formula = "The square of " & CStr(x,0) & " is " &
ToText ({@square, 0) & "."

Rem Formula Square
Global x As Number
formula = x * x
在报表中使用公式 PrintSquare,您得到:
The square of 5 is 0.
在此例中,公式 PrintSquare 使用了公式 Square,因此,Crystal Reports 对其计算顺序进行了排列。首先,对 Square 求值,然后再对 PrintSquare 求值。当对 Square 求值时,全局变量 x 的值为 0,因为这是未初始化的 Number 变量的值。
相反,自定义函数则根据需要求值或者调用。在上一个示例中使用自定义函数:
Rem Formula PrintSquare
formula = "The square of " & CStr (5,0) & " is " &
CStr(cf9Square (5),0) + "."

Rem Custom Function cf9Square
Function cf9Square (x As Number)
cf9Square = x * x
End Function
现在,如果在报表中使用公式 PrintSquare,您将看到:
The square of 5 is 25.



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