|
-
Feb 26th, 2008, 12:28 AM
#1
Thread Starter
Junior Member
Change Machine
Visual Basic - Change Machine?
I am a student at Washington State University and need help with a Change Machine...
Ok How do I make my program execute change. For example, if I have 3 text boxes with Amount of Purchase, Amount Entered, and Change Due. And then 9 check boxes with 20,10,5,1, Dollars,Dimes,Nickels, Pennies and a label box corresponding to each one, and a Calculate Button,how do I make the calculate button correspond with the label boxes corresponding to the number. For example, If I put 20 in for amount of purchase, and 30 for Amount Entered, and the Change Due should be 10. And then in there should be the number one appear in the box next to $10.
I just need help writing the beggining of the code and where at. Then I can take it from there
-
Feb 26th, 2008, 12:43 AM
#2
Re: Change Machine
Since this is an exercise in analysis and not just writing code I'll give you a narrative explanation rather than spoonfeed you with code.
If checkbox for 20 is checked then get number of bills through integral division. You then update change using modular division to get remaining change due less 20 bills. You repeat the process for the rest of denominations.
-
Feb 26th, 2008, 12:47 AM
#3
Thread Starter
Junior Member
Re: Change Machine
Ok Thanks, but can you like just show me how it would look Code wise? i am not asking to be fed the code, I just am a newbie and have no clue what to type it in as. But wouldnt it be \2000 and not \20?
So would it look like
For Private Sub BtnCalculate Click(....
If Chktwenty.Checked=False then
---->intTwenty=intchange\2000
---->intChange=intChangeMod2000
lblTwenty=intTwenty
-
Feb 26th, 2008, 12:48 AM
#4
Re: Change Machine
Yup, you have to work in cents (also adjust change due to cents) cause integral and modular division only works with integers (no decimals), glad you figured that out yourself. See, its an exercise in analysis too and not just writing code. If you didn't adjust to cents then you'd get wrong values; it would then be an opportunity to learn debugging. Those are more important in the long run IMO.
-
Feb 26th, 2008, 12:51 AM
#5
Re: Change Machine
http://www.vbforums.com/showthread.php?t=510765
There's absolutely no point in duplicating questions as it just causes confusion, especialy if you half remove one of them. Now you have 1 and a half threads both with replies.
-
Feb 26th, 2008, 12:54 AM
#6
Thread Starter
Junior Member
Re: Change Machine
 Originally Posted by leinad31
Yup, you have to work in cents (also adjust change due to cents) cause integral and modular division only works with integers (no decimals), glad you figured that out yourself. See, its an exercise in analysis too and not just writing code. If you didn't adjust to cents then you'd get wrong values; it would then be an opportunity to learn debugging. Those are more important in the long run IMO.
Ok wait wait, so then is that put under the btnCalculate section?
So do I put that under 'declare local variable/'import interface/'calculations/'display results?
and when I type in int into the code it says error. Where is the Int in the design?
-
Feb 26th, 2008, 12:57 AM
#7
Re: Change Machine
You have to declare your variables accordingly with correct scope.
As to the button, its a single transaction/process isn't it?
-
Feb 26th, 2008, 01:00 AM
#8
Thread Starter
Junior Member
Re: Change Machine
 Originally Posted by leinad31
You have to declare your variables accordingly with correct scope.
As to the button, its a single transaction/process isn't it?
ok i double click the calculate button and the beggining of the code appears.
I have no clue what to do now, as in How do I make it calculate the cash tendered, amount due and change due into how many 20s,10s,5s,1s, dimes,nickels, pennies, and quarters are given back in the label boxes next to them.
-
Feb 26th, 2008, 01:45 AM
#9
Re: Change Machine
You just repeat the process, only the starting value changes.
If you started with 35 then less one 20 your left with 15. You then repeat process starting with 15 giving you one 10 with 5 left. And so on and so forth.
-
Feb 26th, 2008, 05:59 AM
#10
Addicted Member
Re: Change Machine
For Private Sub BtnCalculate Click(....
If Chktwenty.Checked=False then
---->intTwenty=intchange\2000
---->intChange=intChangeMod2000
lblTwenty=intTwenty
What's the ----> for ??
-
Feb 26th, 2008, 11:25 AM
#11
Thread Starter
Junior Member
Re: Change Machine
Ok so Would my full code look like this....
For Private Sub BtnCalculate Click(....
'calculations
If Chktwenty.Checked=False then
intTwenty=intchange\2000
intChange=intChangeMod2000
lblTwenty=intTwenty
If ChkTen.Checked=False then
inttenn=intchange\1000
intChange=intchangeMod1000
lblTen=intTen
If ChkFive.Checked=False then
intfive=intchange\500
intChange=intchangeMod500
lblFive=intFive
If ChkOne.Checked=False then
intone-intchange\100
intChange=intChangeMod100
lblOne=intOne
-
Feb 26th, 2008, 02:48 PM
#12
Thread Starter
Junior Member
-
Feb 26th, 2008, 04:20 PM
#13
Thread Starter
Junior Member
-
Feb 26th, 2008, 04:41 PM
#14
Re: Change Machine
Please do not bump threads. For some of the reasons, see this
-
Feb 26th, 2008, 07:28 PM
#15
Re: Change Machine
 Originally Posted by DarkFalcon
Leinad31???
Well, have you tried running it? That's often faster than waiting for a reply. Did you get the expected output? What if none of the checkboxes were checked or there is still change left over? Where will you place the amount still left over?
-
Feb 26th, 2008, 08:21 PM
#16
Thread Starter
Junior Member
Re: Change Machine
 Originally Posted by leinad31
Well, have you tried running it? That's often faster than waiting for a reply. Did you get the expected output? What if none of the checkboxes were checked or there is still change left over? Where will you place the amount still left over?
Ok Its not working, because the word intchange is underlined in a blue squiggly. SO how do I make it unsquiggly?
-
Feb 26th, 2008, 10:14 PM
#17
Re: Change Machine
As mentioned in post #7, did you declare your variables properly? Type Option Explicit as the very first line in each of your form/code modules. That will help you trace such errors.
-
Feb 26th, 2008, 10:36 PM
#18
Thread Starter
Junior Member
Re: Change Machine
 Originally Posted by leinad31
As mentioned in post #7, did you declare your variables properly? Type Option Explicit as the very first line in each of your form/code modules. That will help you trace such errors.
Ok, What do I need to delcare, that I am unsure of....
-
Feb 26th, 2008, 10:52 PM
#19
Re: Change Machine
For variable declarations with scope limited to within procedure, something like...
Code:
Option Explicit
Private Sub BtnCalculate Click()
Dim intTwenty As Integer
End Sub
-
Feb 26th, 2008, 10:55 PM
#20
Thread Starter
Junior Member
Re: Change Machine
 Originally Posted by leinad31
For variable declarations with scope limited to within procedure, something like...
Code:
Option Explicit
Private Sub BtnCalculate Click()
Dim intTwenty As Integer
End Sub
But intTwenty isnta variable on the interface though? It says unused local variable for intTwenty when I typed that into the code
-
Feb 27th, 2008, 01:47 AM
#21
Re: Change Machine
Yes, what you see on form are called controls. That code simply declared a variable, which is not a control on the form. Here is a sample that uses (a value was assigned) the variable you declares.
Code:
Option Explicit
Private Sub BtnCalculate Click()
Dim intTwenty As Integer
intTwenty = 20
MsgBox intTwenty
intTwenty = 2008 /2
MsgBox intTwenty
End Sub
-
Feb 27th, 2008, 01:52 AM
#22
Re: Change Machine
leinad31: before you get too involved, you need to understand that Op is using .NET - see: http://www.vbforums.com/showthread.php?t=510926
-
Feb 27th, 2008, 03:55 AM
#23
Re: Change Machine
Question was posted in VB6 section. If he's using .Net then update code accordingly. Algorithm concept stays the same.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|