If ¹Bºâ¦¡¬O³Ì¦³¥Îªº±±¨îµ²ºc¤§¤@¡A¥¦¤¹³\±zÅçºâ¹Bºâ¦¡¤¤ªº±ø¥ó¬O§_¬° True¡A¥H¤Î·í«eªÌ¤£¬° True ®ÉÅçºâ¥t¤@Ó¹Bºâ¦¡¡C
ª`·N ·í®æ¦¡¤Æ±ø¥ó¦¡¤½¦¡®É¡A½Ð¤@©wn¨Ï¥Î ElseÃöÁä¦r¡A§_«h¤£²Å¦X If ±ø¥óªº¼ÆÈ¥i¯à¤£·|«O«ùì©lªº®æ¦¡¡CYnÁ×§Kµo¥Í³oºØ±¡ªp¡A½Ð¨Ï¥Î DefaultAttribute ¨ç¦¡ (If...Else DefaultAttribute)¡C
½d¨Ò
¬Y¤½¥qpµ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¤½¥qn´£¼· 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«ez¤½¥qÁÙn±N¬õ§Qªº³Ì°ª¤Wq¬° $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;
°²³]¬Y¤½¥q·Qnpºâ¨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