Help with code, please?! :)
Hi everyone! I'm new to this forum and to Visual Basic. I don't know much about the language let alone any other language for that matter, but I'm learning. I'm taking this class and we have our 4th and final assignment due on Tuesday and I'm looking to see if anyone can give any insight to see what I'm doing wrong. I'm not asking anyone to do my homework for me, I have my code written out and my programs seem to run fine, but in the end i'm not getting the numbers I should... this is what I mean.
We have to calculate the Net Pay of an employee of a company (Jackson's Jelly Beans, don't ask, it's what the professor used) LOL
And anyway, the way she has us do this is by having 2 input boxes: 1 for number of hours worked, and 2 for hourly rate
Gross Pay is calculated as Number of Hours Worked multiplied by Hourly Rate
and
Payroll Tax is calculated as follows: (and we have a chart)
Gross Pay Payroll Tax
Less than 100 0
$100 - $400.99 4% of Gross Pay greater than $100
$401 - $700.99 $10 plus 6% of Gross Pay greater than $400
More than $701 $28 plus 8% of Gross Pay greater than $700
and then she tells us that Net pay is calculated as Gross Pay minus Payroll Tax (I think this is where I go wrong)
My code so far is:
Option Explicit
Public Const ApplicationTitle = "Jackson's Jelly Beans"
Public Sub Assignment4()
Dim intHours As Integer
Dim intRate As Integer
Dim curGross As Currency
Dim intTax As Integer
intHours = InputBox("Enter Number of Hours Worked", ApplicationTitle, Default:=0)
intRate = InputBox("Enter Hourly Rate", ApplicationTitle, Default:=0)
CurGross = intHours * intRate
Select Case curGross
Case Is <= 100
intTax = 0
Case Is <= 400.99
intTax = 0.04 * curGross
Case Is <= 700.99
intTax = 10 + 0.06 * curGross
Case Else
intTax = 28 + 0.08 * curGross
End Select
MsgBox "Net Pay =" & FormatCurrency(curGross)
End Sub
...so again if anyone can maybe just guide me or point out to me what you think I did wrong. We get some values to try to input into our program to see if we did it right, and although my numbers come up close they don't match, so I know I'm right on the edge of this somewhere. I would love any help I can get. Thank you so much!!!!
~Jill
Re: Help with code, please?! :)
Welcome to the forums!
It's usually a little bit busier around here. When things are slow, you may want to post in the Classic Forum. Back to your program:
You need to subtract the tax!
VB Code:
MsgBox "Net Pay =" & FormatCurrency(curGross - intTax )
and use Code Tags in the future, so it's easy to read:
VB Code:
Option Explicit
Public Sub form_load() ' Assignment4()
Const ApplicationTitle = "Jackson's Jelly Beans"
Dim intHours As Integer
Dim intRate As Integer
Dim curGross As Currency
Dim intTax As Currency
intHours = InputBox("Enter Number of Hours Worked", ApplicationTitle, Default:=0)
intRate = InputBox("Enter Hourly Rate", ApplicationTitle, Default:=0)
curGross = intHours * intRate
Select Case curGross
Case Is < 100
intTax = 0
Case 100 To 400.99
intTax = 0.04 * (curGross - 100)
Case 401 To 700.99
intTax = 10 + (0.06 * (curGross - 400))
Case Else
intTax = 28 + (0.08 * (curGross - 700))
End Select
MsgBox "Net Pay =" & FormatCurrency(curGross - intTax)
End Sub
Re: Help with code, please?! :)
Thanks for the tip! :) I'll remember to post Classic Forum that's probably where most of the users here are anyway, I should've figured. But Thank you so much for helping me out!! :) You're the best!
Re: Help with code, please?! :)
I've made a few changes to correct the numbers. Enjoy!
Re: Help with code, please?! :)
Beaner, the VBA Forum is for questions concerning code dealing with MS Office suite programs and other programs
that also support VBA. VBA is similar to VB but its dependant on Office, usually.
If you are using VB5 or VB6 then the Classic VB Forum is the correct place to post this type of question.
Just a little help on determining where to post future questions. Dont wory if your still unsure, post it and it will get moved
to its appropriate forum.
:)
Re: Help with code, please?! :)
Did the reply from dglienna help?
I suppose the numbers are still not correct.
I was said that:
Quote:
Gross Pay Payroll Tax
Less than 100 0
$100 - $400.99 4% of Gross Pay greater than $100
$401 - $700.99 $10 plus 6% of Gross Pay greater than $400
More than $701 $28 plus 8% of Gross Pay greater than $700
I understand it that way:
Gross Pay 0 to 99,99 0 Tax
Gross Pay 100 to 400,99 Tax 0,04*(GrossPay-100)
Gross Pay 401 to 700,99 Tax 10+0,06*(GrossPay-400)
Gross Pay more than 701 Tax 28+0,08*(GrossPay-700)
Re: Help with code, please?! :)
fixed that, too.
I was looking at the numbers first, and fixed the range. Assumed that the calcs were right, until I heard otherwise. Also, the web page should have been given, which would have given me correct numbers to test it, which I would have done.
No problem, though. It's done now, in VBF.
Re: Help with code, please?! :)
Did you notice it was a school assignment?
So I suppose you get an 'A', dgleinna. :)