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.taiwan.businessobjects.com/
支援服務
http://www.taiwan.businessobjects.com/support/
產品說明文件網站
http://support.businessobjects.com/documentation/