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

If 範例 (Crystal 語法)

假設某公司想要計算每位員工稅款的估計值,並顯示適當的訊息。收入低於 $8,000 不必繳稅,收入介於 $8,000 到 $20,000 稅率為 20%,收入介於 $20,000 到 $35,000 稅率為 29%,收入高於 $35,000 稅率為 40%。
//If example 5
Local CurrencyVar tax := 0;
Local CurrencyVar income := {Employee.Salary};
Local StringVar message := "";
If income < 8000 Then
(
message := "no";
tax := 0
)
Else If income >= 8000 And income < 20000 Then
(
message := "lowest";
tax := (income - 8000)*0.20
)
Else If income >= 20000 And income < 35000 Then
(
message := "middle";
tax := (20000 - 8000)*0.20 + (income - 20000)*0.29
)
Else
(
message := "highest";
tax := (20000 - 8000)*0.20 + (35000 - 20000)*0.29 +
(income - 35000)*0.40
);
//Use 2 decimal places and the comma as a
//thousands separator
Local StringVar taxStr := CStr (tax, 2, ",");
"You are in the " & message & " tax bracket. " &
"Your estimated tax is " & taxStr & "."

附註: 使用變數是為了簡化計算的邏輯。此外,當任何一個條件符合時都會執行兩個運算式,一個是指派變數 tax,另一個是指派變數 message。如果條件的結果會執行多個運算式,這種用法相當有用。



Business Objects, SAP 子公司
http://www.taiwan.businessobjects.com/
支援服務
http://www.taiwan.businessobjects.com/support/
產品說明文件網站
http://support.businessobjects.com/documentation/