Crystal Reports  

If ¹Bºâ¦¡ (Crystal »yªk)

If ¹Bºâ¦¡¬O³Ì¦³¥Îªº±±¨îµ²ºc¤§¤@¡A¥¦¤¹³\±zÅçºâ¹Bºâ¦¡¤¤ªº±ø¥ó¬O§_¬° True¡A¥H¤Î·í«eªÌ¤£¬° True ®ÉÅçºâ¥t¤@­Ó¹Bºâ¦¡¡C

ª`·N   ·í®æ¦¡¤Æ±ø¥ó¦¡¤½¦¡®É¡A½Ð¤@©w­n¨Ï¥Î ElseÃöÁä¦r¡A§_«h¤£²Å¦X If ±ø¥óªº¼Æ­È¥i¯à¤£·|«O«ù­ì©lªº®æ¦¡¡C­Y­nÁ×§Kµo¥Í³oºØ±¡ªp¡A½Ð¨Ï¥Î DefaultAttribute ¨ç¦¡ (If...Else DefaultAttribute)¡C

½d¨Ò

¬Y¤½¥q­pµe´£¼· 4% ªº¬õ§Qµ¹­û¤u¡A¦ý¾P°â³¡ªùªº­û¤u±N¥i±o¨ì 6%¡C¥H¤U¤½¦¡¥Î If ¹Bºâ¦¡«K¥i§¹¦¨¡G

//If example 1
If {­û¤u.³¡ªù} = "Sales" Then
{­û¤u.Á~¤ô} * 0.06
Else
   {Employee.Salary} * 0.04

¦b¥»½d¨Ò¤¤¡A¦pªG±ø¥ó {Employee.Dept} = "Sales" Åçºâ¬° True¡A«h·|°õ¦æ

{­û¤u.Á~¤ô} * 0.06

¹Bºâ¦¡¡F§_«h¡A°õ¦æ Else ¤§«áªº¹Bºâ¦¡¡A¤]´N¬O°õ¦æ

{Employee.Salary} * 0.04

¡C

°²©w¥t¤@®a¤½¥q­n´£¼· 4% ªº¬õ§Q (³Ì¤Ö $1,000) µ¹­û¤u¡C½Ðª`·N½d¨Ò¤¤¨Ã¥¼¥]§t Else ¤l¥y¡A¦]¬° Else ¤l¥y¬O¿ï¾Ü©Êªº¡A¦b¦¹³B¨Ã¤£»Ý­n¡C

//If example 2
Local CurrencyVar bonus := {­û¤u.Á~¤ô} * 0.04;
If bonus < 1000 Then
bonus := 1000;
//The final expression is just the variable ¡¥bonus¡¦.
//This returns the value of the variable and is the
//result of the formula
bonus

§¹¦¨½d¨Ò 2 ªº¥t¤@­Ó¤èªk¬O¨Ï¥Î Else ¤l¥y¡G

//If example 3
Local CurrencyVar bonus := {­û¤u.Á~¤ô} * 0.04;
If bonus < 1000 Then
   1000
Else
bonus

²{¦b°²©w«e­z¤½¥qÁÙ­n±N¬õ§Qªº³Ì°ª¤W­­­q¬° $5,000 ¤¸¡C²{¦b»Ý­n¨Ï¥Îªº¬O ElseIf ¤l¥y¡C¥H¤U½d¨Ò¥u¦³¤@­Ó Else If ¤l¥y¡A¦ý¬O±z¥i¥Hµø»Ý­n¼W¥[¡C

ª`·N   ¨C­Ó If ¹Bºâ¦¡³Ì¦h§¡¥u¯à¦³¤@­Ó Else ¤l¥y¡C

¦pªG¨S¦³¥ô¦ó If ©Î Else If ±ø¥ó¬° True ®É¡A¤~·|°õ¦æ Else ¤l¥y¡C

//If example 4
Local CurrencyVar bonus := {­û¤u.Á~¤ô} * 0.04;
If bonus < 1000 Then
   1000
Else If bonus > 5000 Then
   5000
Else
bonus;

½d¨Ò

°²³]¬Y¤½¥q·Q­n­pºâ¨C¦ì­û¤uµ|´Úªº¦ô­p­È¡A¨ÃÅã¥Ü¾A·íªº°T®§¡C¦¬¤J¦pªG§C©ó $8,000 ¤¸«h¤£¥Îúµ|¡A¦¬¤J¦b $8,000 ¨ì $20,000 ¤¸¤§¶¡ªº»Ýú¯Ç 20% ªºµ|´Ú¡A¦¬¤J¦b $20,000 ¨ì $35,000 ¤¸¤§¶¡ªº»Ýú¯Ç 29% ªºµ|´Ú¡A¦Ó $35,000 ¤¸¥H¤W¦¬¤JªÌ»Ýúµ| 40% ªºµ|´Ú¡C

//If example 5
Local CurrencyVar tax := 0;
Local CurrencyVar income := {­û¤u.Á~¤ô};
Local StringVar message := "";
If income < 8000 Then
(
message := "§K";
tax := 0
)
Else If income >= 8000 And income < 20000 Then
(
message := "³Ì§C";
tax := (income - 8000)*0.20
)
Else If income >= 20000 And income < 35000 Then
(
message := "¤¤µ¥";
tax := (20000 - 8000)*0.20 + (income - 20000)*0.29
)
Else
(
message := "³Ì°ª";
tax := (20000 - 8000)*0.20 + (35000 - 20000)*0.29 +
(income - 35000)*0.40
);
//Use 2 decimal places and the comma as a
//thousand separator
Local StringVar taxStr := CStr (tax, 2, ",");
"±zÄÝ©ó " & message & " úµ|Ãþ§O¡C " &
"±zªº¹w¦ôµ|ÃB¬° " & taxStr & "¡C"
ª`·N   ¨Ï¥ÎÅܼƬO¬°¤F²¤Æ­pºâªºÅÞ¿è¡C¦¹¥~¡A¥ô¦ó¤@­Ó±ø¥ó²Å¦X®É³£·|°õ¦æ¨â­Ó¹Bºâ¦¡¡A¤@­Ó¬O«ü¬£ÅÜ¼Æ tax¡A¥t¤@­Ó¬O«ü¬£ÅÜ¼Æ message¡C¦pªG±ø¥óªºµ²ªG·|°õ¦æ¦h­Ó¹Bºâ¦¡¡A³oºØ¥Îªk¬Û·í¦³¥Î¡C

½Ð°Ñ¾\

Grouping ¹Bºâ¦¡