0

以下は、Excel 2010 を使用して Youtube チュートリアルから抽出したコードの一部です。Mac 用の Excel 2011 でこれを実行しようとすると、通貨の出力はすべて整数になります。このバージョンの Excel では FormatCurrency() の動作が異なりますか? それとも、(また)何かを台無しにしただけですか?助けてくれてありがとう。

ベスト、トニー・リマ

Option Explicit
' Tony Lima, July 23, 2014

Const SCOOPPRICE As Double = 0.75
Const TIPPERCENT As Double = 0.15

' ****************************************
' Ice cream store order and print receipt
' *****************************************

Private Sub btnOrder_Click()
    Dim numScoops As Integer
    Dim scoopCost As Double
    Dim tipAmount As Double
    Dim totalCost As Double

    '*** get the number of scoops ordered
    numScoops = CInt(txtScoops.Text)
    '*** calculate cost of ice cream and tip amount
    scoopCost = numScoops * SCOOPPRICE
    tipAmount = scoopCost * TIPPERCENT
    '*** add the two to get the total cost
    totalCost = scoopCost + tipAmount

    '*** print receipt
    lstReceipt.AddItem ("Thanks for your order!")
    lstReceipt.AddItem ("")
    lstReceipt.AddItem ("You ordered " & CStr(numScoops) & " scoops of ice cream")
    lstReceipt.AddItem ("Cost of ice cream " & FormatCurrency(scoopCost, 2))
    lstReceipt.AddItem ("Tip (thank you) " & FormatCurrency(tipAmount, 2))
    lstReceipt.AddItem ("Total cost " & FormatCurrency(totalCost, 2))

End Sub
4

1 に答える 1

0

コードは Windows 7 PC 上の Excel 2010 で正常に動作します。VBE のイミディエイト ウィンドウを使用してみて、debug.print ステートメントをいくつか挿入して、何が起こっているかを確認してください。

Debug.print FormatCurrency(scoopCost,2) for example...

それが機能することを知っておくべきだと思っただけです。

于 2014-07-24T16:57:33.217 に答える