473,385 Members | 1,531 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Visual Basic Change Denomination Help

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
3 6787
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
Pritul
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
Try this:

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

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

Similar topics

1
by: angelag | last post by:
I am currently taking a college course in Visual Basic.Net and I am a beginner. I bought Visual Studio.Net 2003 to do my homework at home. I built my first project and e-mailed it to myself at...
2
by: AK | last post by:
I don't want any part of the previous discussion on Visual Basic versus Visual Basic.Net. My query is about using Visual Basic for Applications; and whether it is better to use Visual Basic 6 or...
2
by: Ralph | last post by:
I used to have Visual Basic .net std. 2003 installed on WinXP SP1A. But I found it too hard to upgrade WinXP to SP2. Now, I do have WinXP SP2 installed, but I am having problems installing...
2
by: Robert Mileski | last post by:
I've made some program in Visual Basic 2005 that works with changing files and folders. After I've finished it, the main problem is to refresh the Windows OS. I mean the same thing as when we press...
97
by: Master Programmer | last post by:
An friend insider told me that VB is to be killled off within 18 months. I guess this makes sence now that C# is here. I believe it and am actualy surprised they ever even included it in VS 2003 in...
3
by: Daron | last post by:
Is it possible to use SQL to take a field, and break it down by denominations? I would like to take a field, and then break this out into the number of bills($100's, $50's, etc) I would need:...
4
by: Chris Asaipillai | last post by:
Hi there My compay has a number of Visual Basic 6 applications which are front endeed onto either SQL Server or Microsoft Access databases. Now we are in process of planning to re-write these...
1
by: =?Utf-8?B?RHVzdGlu?= | last post by:
I am trying to build a program for the first time in Visual Basic. I work for a public utility and we will use to track our crews during large outages. It is a simple program with 16 lines of text...
27
by: geniet | last post by:
Hello all of you, I have some problem in setting cells values (or fromat or...) in my Excel spreadsheet using a VB statement like within my Module: Range("C1").Value = 20 I have this in a...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.