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 & "."

計算の手順を単純化するために変数を使用しています。また、条件の 1 つが満たされた場合には、2 つの式が実行されます。1 つは tax 変数への代入、もう 1 つは message 変数への代入です。条件の評価の結果として複数の式を実行する方法はよく使用されます。



Business Objects, an SAP company
http://japan.businessobjects.com/
サポート サービス
http://japan.businessobjects.com/support/
Web 上の製品マニュアル
http://support.businessobjects.com/documentation/