0

Below is some code I extracted from a Youtube tutorial using Excel 2010. When I try to run this on Excel 2011 for the Mac, the currency outputs are all integers. Does FormatCurrency() work differently in this version of Excel? Or have I just screwed up something (again)? Thanks for any help.

Best, Tony Lima

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
Community
  • 1
  • 1
Tony Lima
  • 65
  • 1
  • 9

1 Answers1

0

Code works fine in Excel 2010 on Windows 7 pc. Try using the immediate window in the VBE and pepper some debug.print statements in to see what's going on.

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

Just thought you should know that it does work.

BeachBum68
  • 96
  • 9
  • I kind of figured it was a 2011 issue. Thanks for the tip -- I'll try it later today and report the results. – Tony Lima Jul 24 '14 at 18:48
  • It's something in the code. FormatCurrency(200.00, 2) returns $200.00 in the immediate window. Same result using 200 instead of 200.00. If I figure out what's going on I'll post here. – Tony Lima Jul 24 '14 at 20:33
  • After a closer look, it's not $200.00, but $200 00. Bug in FormatCurrency() fwiw. – Tony Lima Jul 24 '14 at 20:55
  • In Excel 2011 you need to use Format(, "Currency") - works for FormatPercent, too. – Tony Lima Aug 08 '14 at 00:25
  • Cool! That's good to know. Also, kinda disturbing that MS changes something like that from version to version/platform to platform... You would think they would be more consistent. "It's not a bug... _it's a feature_" – BeachBum68 Aug 13 '14 at 15:07