Results 1 to 14 of 14

Thread: Information/Website(s) on how to make a employee tax calculator

  1. #1

    Thread Starter
    Member
    Join Date
    Apr 2013
    Posts
    55

    Information/Website(s) on how to make a employee tax calculator

    Hi.

    Been working on a payroll system for a while now for a college project..Finally got to the stage of calculating the tax for the staff (Which is rather important lol)

    I'm VERY new to VB and this project doesn't have to be perfect...if i'm honest i think all the database side of it is wrong...however it works(ish)

    Math isn't my strong point so iv very confused about Tax etc.

    So far i have wrote a code which works...

    txtTotal.Text = Val(txtHours.Text) * Val(txtPay.Text) * 4
    decIncome = Convert.ToDecimal(txtTotal.Text)
    decDeductions = decIncome * 0.22
    decAmount = decIncome - decDeductions

    txtTotal.Text = decIncome
    txtTax.Text = decDeductions
    txtNetpay.Text = decAmount


    I know i have 22% as Tax...it was just a test to see if it works..and it did.

    Basically i'm looking for some help from someone that's good with tax etc...Because i'm totally lost!

    Will upload my project if you anyone wants to see it all...Its dreadful mind!

    Thanks.

  2. #2
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Posts
    12,376

    Re: Information/Website(s) on how to make a employee tax calculator

    What specific questions do you have? While you use some vb6 holdovers I can't see anything wrong off the top of my head(by the way wrap your code in tags).
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | HtmlLessons | CssLessons | Code Tags | Sword of Fury - Jameram

  3. #3

    Thread Starter
    Member
    Join Date
    Apr 2013
    Posts
    55

    Re: Information/Website(s) on how to make a employee tax calculator

    Hi,

    Thanks for the quick reply,

    the code does work...But i need it to 20% tax (i think i'm not sure how to work the Tax out?) but it will not let me,every time i enter 0.20 it changes to 0.2

    I'm from the UK and i have run up on the Tax but its not making sense...think i said maths is not my strong point

  4. #4
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Posts
    12,376

    Re: Information/Website(s) on how to make a employee tax calculator

    Yeah, by default visual studio's removes any additional, unnecessary 0's. To display your final result in a currency format you'd add:
    Code:
    decIncome.ToString("c")
    What you're doing is formatting the string. Take a look at this MSDN article on standard numeric format strings. But (1 * .2) and (1 * .20) will return the same result.
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | HtmlLessons | CssLessons | Code Tags | Sword of Fury - Jameram

  5. #5

    Thread Starter
    Member
    Join Date
    Apr 2013
    Posts
    55

    Re: Information/Website(s) on how to make a employee tax calculator

    Great thank you dday9 i will carry on and hopefully not mess anything else up...well i can hope!

  6. #6

    Thread Starter
    Member
    Join Date
    Apr 2013
    Posts
    55

    Re: Information/Website(s) on how to make a employee tax calculator

    Sorry where do i did
    decIncome.ToString("c")
    again?

  7. #7

    Thread Starter
    Member
    Join Date
    Apr 2013
    Posts
    55

    Re: Information/Website(s) on how to make a employee tax calculator

    add i meant oopes

  8. #8
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Posts
    12,376

    Re: Information/Website(s) on how to make a employee tax calculator

    By the way, I would like to point out a few things:
    1) You should really turn option strict and explicit on
    2) You shouldn't use val or convert.todecimal. Val will always return the value where it's not a number. ie - 1,200 will return a 1 -or- 15.5 will return a 15. Instead integer/decimal/double .Parse or .TryParse should be used when converting a string to any numeric type.

    Taking advantage of the suggestions provided will greatly increase the efficiency of your application, it will also prevent many errors from coming up later on down the road.

    Edit - So one change would be:
    Code:
            Dim hours, pay As Decimal
            If Decimal.TryParse(txtHours.Text, hours) AndAlso Decimal.TryParse(txtPay.Text, pay) Then
                Dim tot As Decimal = hours * pay * 4
                txtTotal.Text = tot.ToString("c")
            End If
    Last edited by dday9; Apr 25th, 2013 at 10:25 AM.
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | HtmlLessons | CssLessons | Code Tags | Sword of Fury - Jameram

  9. #9
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Posts
    12,376

    Re: Information/Website(s) on how to make a employee tax calculator

    Quote Originally Posted by jaisdavies View Post
    Sorry where do i did again?
    Here:
    Code:
    txtTotal.Text = decIncome.ToString("c")
    The same goes for:
    Code:
    txtTax.Text = decDeductions.ToString("c")
     txtNetpay.Text = decAmount.ToString("c")
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | HtmlLessons | CssLessons | Code Tags | Sword of Fury - Jameram

  10. #10
    PowerPoster Evil_Giraffe's Avatar
    Join Date
    Aug 2002
    Location
    Suffolk, UK
    Posts
    2,555

    Re: Information/Website(s) on how to make a employee tax calculator

    Quote Originally Posted by jaisdavies View Post
    Code:
            decIncome = Convert.ToDecimal(txtTotal.Text)
            decDeductions = decIncome * 0.2
    Okay, I've changed it to 20% tax as it doesn't make any difference to the point I'm about to make.

    Suppose that the taxable income comes out to £1000.01
    Now, what should the tax on that be? As it stands, the person is going to be taxed £200.002. That's 200 pounds and 0.2 of a penny. Does that make sense in any way?

    There's something fundamental that you've forgotten and that's rounding. Whenever you do a calculation with money you need to do two things: firstly use a Decimal type rather than Double (which you've done, was that on purpose or just luck?) the second is work out when you need to round. In this simplistic scenario, you just need to round to 2 d.p. after calculating the percentage, but make sure that you round correctly - the built in rounding functions may not match the behaviour that is very well defined by the tax code! (This is where you need to have access to a domain expert - someone who knows (in this case) how the tax calculations should be carried out and can validate that your results are correct, and tell you about all the corner cases and what not.)

  11. #11

    Thread Starter
    Member
    Join Date
    Apr 2013
    Posts
    55

    Re: Information/Website(s) on how to make a employee tax calculator

    Hi Evil_Giraffe,

    Thanks for the reply,

    if i'm honest i can't work out Tax at well..can't even work it out on my payslip at the end of the month haha so to try and make it work via code in a program that I've only been learning for a few months is a lot to ask!

    Been looking online hoping that someone is in the same shoes as me but can't find some information.

    This form is the best however people i'm great full of the help you guys give

  12. #12

    Thread Starter
    Member
    Join Date
    Apr 2013
    Posts
    55

    Re: Information/Website(s) on how to make a employee tax calculator

    txtTotal.Text = decIncome.ToString("c")
    txtTax.Text = decDeductions.ToString("c")
    txtNetpay.Text = decAmount.ToString("c")


    txtTotal.Text = Val(txtHours.Text) * Val(txtPay.Text) * 4
    decIncome = Convert.ToDecimal(txtTotal.Text)
    decDeductions = decIncome * 0.2
    decAmount = decIncome - decDeductions
    txtTotal.Text = decIncome
    txtTax.Text = decDeductions
    txtNetpay.Text = decAmount
    Is this right guys?

    the £ sign still isnt showing up in front of the amount...is it because its linked to access? via databinding?

  13. #13

    Thread Starter
    Member
    Join Date
    Apr 2013
    Posts
    55

    Re: Information/Website(s) on how to make a employee tax calculator

    Sorted now.

    I added it to the end of the code..Oopes.

    but yey im learning haha

  14. #14
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Information/Website(s) on how to make a employee tax calculator

    Quote Originally Posted by jaisdavies View Post
    if i'm honest i can't work out Tax at well..can't even work it out on my payslip at the end of the month haha so to try and make it work via code in a program that I've only been learning for a few months is a lot to ask!

    Been looking online hoping that someone is in the same shoes as me but can't find some information.
    All of the information you need is here:
    http://www.hmrc.gov.uk/incometax/

    There are lots of issues to contend with, especially the fact that the rules and allowances change a bit each year (such as age based things changing quite a bit this year).

    If you take the simplest case for the current tax year (somebody who was born after 5 April 1948, isn't married, isn't blind, and earns less than £100000):
    • the first £9440 of earnings are tax free,
    • the next £32010 is taxed at 20%,
    • anything over that is taxed at 40%

    ...so somebody who earns £29440 will pay £4000 tax (as they get £9440 tax free, then pay 20% of the remaining £20000).

    As this all changes a bit each year, you will probably need to store the relevant limits/date ranges/etc so that your program can work it out for previous/future years data when needed. You may also want to provide an interface for the users to specify those items for the next tax year, so that you don't have to modify the program every year.


    You may or may not want to account for National Insurance too, the information for that is also available via the link above.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width