432,257 Members | 928 Online + 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   Private Sub uiCalButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles uiCalButton.Click 'declare variables  Dim amountOwed, amountPaid, changeDue As Decimal Const dollar As Decimal = 1D Const quarters As Decimal = 0.25D Const dimes As Decimal = 0.1D Const nickels As Decimal = 0.05D Const pennies As Decimal = 0.01D Dim dollarChange As Integer Dim quarterChange As Integer Dim dimeChange As Integer Dim nickelChange As Integer Dim pennyChange As Integer   'assign value to variables amountOwed = Decimal.Parse(Me.uiOwedTextBox.Text) amountPaid = Decimal.Parse(Me.uiPaidTextBox.Text)   'perform calculations changeDue = amountPaid - amountOwed dollarChange = Convert.ToInt32(changeDue) \ 100 quarterChange = Convert.ToInt32(changeDue) \ 25 dimeChange = Convert.ToInt32(changeDue) \ 10 nickelChange = Convert.ToInt32(changeDue) \ 5 pennyChange = Convert.ToInt32(changeDue) \ 1     'display total amounts in controls Me.uiChangeLabel.Text = Convert.ToString(changeDue) Me.uiDollarLabel.Text = Convert.ToString(dollarChange) Me.uiQuarterLabel.Text = Convert.ToString(quarterChange) Me.uiDimeLabel.Text = Convert.ToString(dimeChange) Me.uiNickelLabel.Text = Convert.ToString(nickelChange) Me.uiPennyLabel.Text = Convert.ToString(pennyChange)   Me.uiChangeLabel.Text = Format(changeDue, "currency")   'send focus to the clear form Me.uiClearForm.Focus() End Sub   Feb 7 '06 #1
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 