By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,257 Members | 928 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,257 IT Pros & Developers. It's quick & easy.

Visual Basic Change Denomination Help

P: 6
I need to write a code that calculates the change due after the user has input the amount owed and amount paid. This is easy enough! :rolleyes:
My problem comes in when the program wants you to count how many dollars, quarters, dimes, and pennies are due from this change. :confused:

Can someone please help me with this? I don't know where to put my variables to make the computer compute this. :o

Here is my code. P.S. It doesn't work!

Expand|Select|Wrap|Line Numbers
  1.  
  2. Private Sub uiCalButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles uiCalButton.Click
  3. 'declare variables 
  4. Dim amountOwed, amountPaid, changeDue As Decimal
  5. Const dollar As Decimal = 1D
  6. Const quarters As Decimal = 0.25D
  7. Const dimes As Decimal = 0.1D
  8. Const nickels As Decimal = 0.05D
  9. Const pennies As Decimal = 0.01D
  10. Dim dollarChange As Integer
  11. Dim quarterChange As Integer
  12. Dim dimeChange As Integer
  13. Dim nickelChange As Integer
  14. Dim pennyChange As Integer
  15.  
  16. 'assign value to variables
  17. amountOwed = Decimal.Parse(Me.uiOwedTextBox.Text)
  18. amountPaid = Decimal.Parse(Me.uiPaidTextBox.Text)
  19.  
  20. 'perform calculations
  21. changeDue = amountPaid - amountOwed
  22. dollarChange = Convert.ToInt32(changeDue) \ 100
  23. quarterChange = Convert.ToInt32(changeDue) \ 25
  24. dimeChange = Convert.ToInt32(changeDue) \ 10
  25. nickelChange = Convert.ToInt32(changeDue) \ 5
  26. pennyChange = Convert.ToInt32(changeDue) \ 1
  27.  
  28.  
  29. 'display total amounts in controls
  30. Me.uiChangeLabel.Text = Convert.ToString(changeDue)
  31. Me.uiDollarLabel.Text = Convert.ToString(dollarChange)
  32. Me.uiQuarterLabel.Text = Convert.ToString(quarterChange)
  33. Me.uiDimeLabel.Text = Convert.ToString(dimeChange)
  34. Me.uiNickelLabel.Text = Convert.ToString(nickelChange)
  35. Me.uiPennyLabel.Text = Convert.ToString(pennyChange)
  36.  
  37. Me.uiChangeLabel.Text = Format(changeDue, "currency")
  38.  
  39. 'send focus to the clear form
  40. Me.uiClearForm.Focus()
  41. End Sub
  42.  
Feb 7 '06 #1
Share this Question
Share on Google+
3 Replies


P: 3
Example of Determining Chage Denominations in Visual Basic Code

I haven't tested it myself as I'm not working with VB for awhile but it looks sound.

;)
Feb 8 '06 #2

P: 3
Im having a problem, its been sort of bugging me out.
If a user does not enter a value in a textbox on a form, I want to display a erroe message. A sort of validation.

I have tried loads of thing, one is:-

If stockpricet.value = " " Then
MsgBox "Value not entered"
End If

can any body help?

Pritul
Feb 10 '06 #3

P: 3
Try this:

If Len(stockPricet.Text) = 0 Then
MsgBox "Value not entered", vbOkay
End If
Feb 10 '06 #4

Post your reply

Sign in to post your reply or Sign up for a free account.