Re: still can't calculate
Try this:
private Sub cmdCalc_Click()
Dim iDollars as Long
Dim iQuarters as Long
Dim iDimes as Long
Dim iNickels as Long
Dim iPennies as Long
'assign values to variables
iPennies = CLng(Val(InputBox("Enter the number of pennies", "Number of Pennies")))
'perform calculations
iDollars = Int(iPennies / 100)
iQuarters = Int((iPennies - (iDollars * 100)) / 25)
iDimes = Int((iPennies - (iQuarters * 25) - (iDollars * 100)) / 10)
iNickels = Int((iPennies - (iDimes * 10) - (iQuarters * 25) - (iDollars * 100)) / 5)
iPennies = Int(iPennies - (iNickels * 5) - (iDimes * 10) - (iQuarters * 25) - (iDollars * 100))
lblNDollars = "Dollars: " & iDollars
lblNQuarters = "Quarters: " & iQuarters
lblNDimes = "Dimes: " & iDimes
lblNNickels = "Nickels: " & iNickels
lblNPennies = "Pennies: " & iPennies
End Sub
Aaron Young
Analyst Programmer
[email protected]
[email protected]
Re: still can't calculate
Your problem is not with the val function, it's with your actual calculations. VB does not follow the MDAS (mult, div, add, subtract) convention as a language such as Fortran would. You need to change this part of your code to:
'perform calculations
sngDollars = CSng(intPennies) / 100
sngQuarters = (CSng(lblNdollars.Caption) - CSng(intPennies))/ 25
sngDimes = (CSng(lblNquarters.Caption) - CSng(intPennies))/ 10
sngNickels = (CSng(lblNdimes.Caption) - CSng(intPennies)) / 5
sngNPennies = CSng(intPennies) / 1 ' why?
Sky1000
Re: still can't calculate
Thanks for the help! You're a lifesaver!
kazooie21