Crystal Reports for Rational Application Developer 設計工具指南

使用 If 運算式 (Crystal 語法)

If 運算式是 Crystal 語法中使用最廣泛的命令,它也讓您能夠了解運算式的本質。請將前面的 If 運算式視為一個獨立的公式。請注意,因為這個公式是一個單一運算式,所以不需要分號:
If {Orders Detail.Quantity} > 1 Then
"multiple units"
Else
"one unit"
假設您想要修改這個公式,使它印出「多重單位」或數字 1。
//An erroneous formula
If {Orders Detail.Quantity} > 1 Then
"multiple units"
Else
1
本公式將會導致錯誤,其原因是這個運算式中的值屬於不同的型別,「多重單位」是字串值,而 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.taiwan.businessobjects.com/
支援服務
http://www.taiwan.businessobjects.com/support/
產品說明文件網站
http://support.businessobjects.com/documentation/