Results 1 to 27 of 27

Thread: I need help with creating a payroll in visual basic

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2013
    Posts
    14

    I need help with creating a payroll in visual basic

    create an application that displays payroll information. The application should allow the user to enter the following data for four employees:
    number of hours worked
    hourly pay rate
    percentage to be withheld for state income tax
    percentage to be withheld for federal income tax
    percentage to be withheld fo FICA

    The application should calculate and display the following data for each employee in a list box:
    gross pay (the number of hours worked multiplied by hourly pay rate)
    state income tax withholdings (gross pay multiplied by state income tax percentage)
    federal income tax withholdings (gross pay multiplied by federal income tax percentage)
    FICA withholdings (gross pay multiplied by FICA percentage)
    net pay (the gross pay minus state income tax, federal income tax, and FICA)

    When the calculations are performed, be sure to check for the following error:
    if an employee's state income tax plus federal tax plus FICA is greater than the employee's gross pay, display an error message stating that the withholdings are too great.
    Be sure to add appropriate ToolTips for each control on the form.

  2. #2
    Frenzied Member
    Join Date
    Feb 2008
    Location
    Texas
    Posts
    1,288

    Re: I need help with creating a payroll in visual basic

    So you have your requirements done, what code have you written so far?
    You down with OOP? Yeah you know me!
    MCAD and MCMICKEYMOUSE (vb.net)

    ----

    If it even kinda helps... rate it : )

    Edit a Multi-page .tif file and save.

  3. #3

    Thread Starter
    New Member
    Join Date
    Nov 2013
    Posts
    14

    Re: I need help with creating a payroll in visual basic

    Name:  poi.jpg
Views: 10820
Size:  123.0 KB
    This is all I have done so far

  4. #4
    Frenzied Member
    Join Date
    Oct 2012
    Location
    Tampa, FL
    Posts
    1,187

    Re: I need help with creating a payroll in visual basic

    A picture of the UI != code

  5. #5

    Thread Starter
    New Member
    Join Date
    Nov 2013
    Posts
    14

    Re: I need help with creating a payroll in visual basic

    Name:  ouu.jpg
Views: 14977
Size:  139.0 KB

  6. #6
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    39,043

    Re: I need help with creating a payroll in visual basic

    But it is enough to know that it won't quite be sufficient.

    That form would allow you to enter information for one employee, or to show information for one employee, but how will you use that to deal with four employees? How were you figuring you would move from one employee to the next? One of the things you'd have to do for that navigation is to be able to store the information for each employee. Technically, that's not so difficult, but since this is an assignment, you are probably limited to the things you have already learned. So, have you learned classes yet? If not, how about arrays or better yet, Lists?
    My usual boring signature: Nothing

  7. #7
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    39,043

    Re: I need help with creating a payroll in visual basic

    Posting pictures isn't a good way to go here. Post the code directly, properly wrapped in [Code] [/CODE] tags.
    My usual boring signature: Nothing

  8. #8

    Thread Starter
    New Member
    Join Date
    Nov 2013
    Posts
    14

    Re: I need help with creating a payroll in visual basic

    'input variable declaration.
    Dim hoursWorked As Decimal
    Dim payrate As Decimal
    Dim stateincometax As Decimal
    Dim federalincometax As Decimal
    Dim FICA As Decimal


    'Getting input.
    strname = InputBox("Enter Name:", "Enter Input")
    'Calculate grosspay, stateIncome, federalIncome, fica and netpay.
    dblgrosspay = inthour * inthourRate
    dblstateIncome = dblgrosspay * dblstate
    dblfederalIncome = dblgrosspay * dblfederal
    dblfica = dblgrosspay * fciaIn

  9. #9
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    39,043

    Re: I need help with creating a payroll in visual basic

    Ok, that's something...but what? For one thing, you should wrap code in the tags that I mentioned.

    Some people, and therefore some classes, still like warting variables, which is what you are doing with the prepended int and dbl. There isn't much point in that anymore, though I still do a small amount of it to make things group together in intellisense, and to tell me the scope of some variables. However, in this case it leads to a few questions:

    1) If intHourRate really is an Integer, that's a problem. Few people are paid an integer amount as an hourly rate. More typically, they are paid a Decimal amount. If you are taking a Decimal value and stuffing it into an integer, you will lose the decimal portion of the number.

    2)You have a few locally declared variables, such as Dim FICA As Decimal, but then you use fciaIn. Where did fciaIn come from? What is the point of declaring the FICA variable if you never put anything into it and never use it anywhere? The same could be said of dblState vs. stateincometax, and the rest.

    3) When working with money, Decimal is the right type, but the warting suggests that you are turning much of this into type Double. It should all be Decimal and remain Decimal, otherwise you will get odd rounding issues in some cases.

    4) Where are you storing the information for each person?
    My usual boring signature: Nothing

  10. #10

    Thread Starter
    New Member
    Join Date
    Nov 2013
    Posts
    14

    Re: I need help with creating a payroll in visual basic

    could you write this in code? so I can understand it better

  11. #11

    Thread Starter
    New Member
    Join Date
    Nov 2013
    Posts
    14

    Re: I need help with creating a payroll in visual basic

    can someone please help me out

  12. #12
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    39,043

    Re: I need help with creating a payroll in visual basic

    Write what in code? I'm not sure I said anything that translates into much code. You have some variables that you don't appear to be declaring. Either they are declared at form scope and not in the method, or they are not declared at all. The latter would be a problem, but there isn't much writing to do for that.
    My usual boring signature: Nothing

  13. #13

    Thread Starter
    New Member
    Join Date
    Nov 2013
    Posts
    14

    Re: I need help with creating a payroll in visual basic

    This is all I have written what should I do next is what am asking
    Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click
    'input variable declaration.
    Dim hoursWorked As Decimal
    Dim payrate As Decimal
    Dim stateincometax As Decimal
    Dim federalincometax As Decimal
    Dim FICA, fciaIn As Decimal

  14. #14
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    39,043

    Re: I need help with creating a payroll in visual basic

    Those look like variables to hold the inputs, so you would convert the inputs into the variables using Decimal.TryParse:

    Code:
    If Decimal.TryParse(someTextbox.Text, hoursWorked) Then
     'It was a decimal and was parsed into the hoursWorked variable.
    Else
     'It was not a decimal, so put up a messagebox and exit the sub.
    End If
    Of course, I don't know what the names of the controls are, so I used a dummy value for the textbox name, but you know what the names are, so you can correct that.
    My usual boring signature: Nothing

  15. #15

    Thread Starter
    New Member
    Join Date
    Nov 2013
    Posts
    14

    Re: I need help with creating a payroll in visual basic

    here is my code
    Public Class Form1

    Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click

    'input variable declaration.
    Dim Name As Decimal
    Dim hoursWorked As Decimal
    Dim payrate As Decimal
    Dim stateincometax As Decimal
    Dim federalincometax As Decimal
    Dim FICA, fciaIn As Decimal

    If Decimal.TryParse(txtname.Text, Name) Then
    'it was a decimal and was parsed into the name variable.
    Else
    'It was not a decimal, so put a messagebox and exit the sub.
    End If

    If Decimal.TryParse(txthours.Text, hoursWorked) Then
    'It was a decimal and was parsed into the hoursWorked variable.
    Else
    'It was not a decimal, so put up a messagebox and exit the sub.
    End If

    If Decimal.TryParse(txtrate.Text, payrate) Then
    'It was a decimal and was parsed into the payrate variable.
    Else
    ' It was not a decimal, so put up a messagebox and exit the sub.
    End If

    If Decimal.TryParse(txtstate.Text, stateincometax) Then
    'It was a decimal and was parsed into the stateincometax variable.
    Else
    'It was not a decimal, so put a messagebox and exit the sub.

    End If

    If Decimal.TryParse(txtfederal.Text, federalincometax) Then
    'It was a decimal and was parsed into the federalincometax variable.
    Else
    'It was not a decimal, so put a messagebox exit the sub.
    End If
    If Decimal.TryParse(txtFICA.Text, FICA) Then
    'It was a decimal and was parsed into the FICA variable.
    Else
    'It was not a decimal, so put a messagebox exit the sub.

    End If

    If Decimal.TryParse(txtFICA.Text, fciaIn) Then
    'It was a decimal and was parsed into the fciaIn variable.
    Else
    'It was not a decimal, so put a messagebox exit the sub.
    End If
    End Sub
    Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
    txtstate.Text = " "
    txtfederal.Text = " "
    txtFICA.Text = " "
    txthours.Text = " "
    txtrate.Text = " "
    txtName.Text = " "
    IstOutput.Items.Clear()
    txtName.Focus()
    End Sub

    Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
    Me.Close()
    End Sub
    End Class

    clear and exit is working but calculate isnt

  16. #16
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,760

    Re: I need help with creating a payroll in visual basic

    Hi t - baby, welcome to the forums.

    I know shaggy mentioned earlier that you need to wrap your code in code tags: [code]'Hello World[/code] please do so. It properly formats your code, for example your btnClear and btnExit code wrapped in code tags look like this:

    Code:
        Private Sub btnClear_Click(sender As System.Object, e As System.EventArgs) Handles btnClear.Click
            txtstate.Text = " "
            txtfederal.Text = " "
            txtFICA.Text = " "
            txthours.Text = " "
            txtrate.Text = " "
            txtname.Text = " "
            IstOutput.Items.Clear()
            txtname.Focus()
        End Sub
    
        Private Sub btnExit_Click(sender As System.Object, e As System.EventArgs) Handles btnExit.Click
            Me.Close()
        End Sub
    As for the reason why your btnCalculate isn't working, it's because you haven't written any code for it. You just check if the user entered in a decimal, but then comment everything out.

    Also, should name be declared as a decimal or should it be declared as a string?
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  17. #17

    Thread Starter
    New Member
    Join Date
    Nov 2013
    Posts
    14

    Re: I need help with creating a payroll in visual basic

    it should be written as string, can you help me with the code for calculate??

  18. #18
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,760

    Re: I need help with creating a payroll in visual basic

    No because I'm not a math guy. Come up with the equations to calculate these four things:

    1. hourly pay rate
    2. percentage to be withheld for state income tax
    3. percentage to be withheld for federal income tax
    4. percentage to be withheld fo FICA


    and I can help you convert those equations into code.
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  19. #19

    Thread Starter
    New Member
    Join Date
    Nov 2013
    Posts
    14

    Re: I need help with creating a payroll in visual basic

    hourly pay rate <= 20
    percentage for state income tax = 2%
    percentage for federal income tax = 5%
    percentage for FICA = 3%
    is this okay??

  20. #20
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,760

    Re: I need help with creating a payroll in visual basic

    Well, that's not what I meant... Let's work this out. I would first change your code in the calculation. The first change is to the name:
    Code:
            Dim Name As String = txtname.Text
            Dim hoursWorked As Decimal
            Dim payrate As Decimal
            Dim stateincometax As Decimal
            Dim federalincometax As Decimal
            Dim FICA, fciaIn As Decimal
    The next change will be to use AndAlso when trying to convert the text to a decimal, and if any of them fail, let the user know:
    Code:
            Dim Name As String = txtname.Text
            Dim hoursWorked As Decimal
            Dim payrate As Decimal
            Dim stateincometax As Decimal
            Dim federalincometax As Decimal
            Dim FICA, fciaIn As Decimal
    
            If Decimal.TryParse(txthours.Text, hoursWorked) AndAlso _
                Decimal.TryParse(txtrate.Text, payrate) AndAlso _
                Decimal.TryParse(txtstate.Text, stateincometax) AndAlso _
                Decimal.TryParse(txtfederal.Text, federalincometax) AndAlso _
                Decimal.TryParse(txtFICA.Text, FICA) Then
    
            Else
                MessageBox.Show("One or more text fields has an invalid input.")
            End If
    Next, let's work on the equations:
    1. gross pay (the number of hours worked multiplied by hourly pay rate)
    2. state income tax withholdings (gross pay multiplied by state income tax percentage)
    3. federal income tax withholdings (gross pay multiplied by federal income tax percentage)
    4. FICA withholdings (gross pay multiplied by FICA percentage)
    5. net pay (the gross pay minus state income tax, federal income tax, and FICA)


    Those are simple equations:
    Code:
            Dim Name As String = txtname.Text
            Dim hoursWorked As Decimal
            Dim payrate As Decimal
            Dim stateincometax As Decimal
            Dim federalincometax As Decimal
            Dim FICA, fciaIn As Decimal
    
            If Decimal.TryParse(txthours.Text, hoursWorked) AndAlso _
                Decimal.TryParse(txtrate.Text, payrate) AndAlso _
                Decimal.TryParse(txtstate.Text, stateincometax) AndAlso _
                Decimal.TryParse(txtfederal.Text, federalincometax) AndAlso _
                Decimal.TryParse(txtFICA.Text, FICA) Then
    
                Dim grosspay As Decimal
                Dim statewithholdings As Decimal
                Dim federalwithholdings As Decimal
                Dim ficawithholdings As Decimal
                Dim netpay As Decimal
    
                grosspay = hoursWorked * payrate
                statewithholdings = grosspay * stateincometax
                federalwithholdings = grosspay * federalincometax
                ficawithholdings = grosspay * FICA
                netpay = grosspay - statewithholdings - federalwithholdings - ficawithholdings
            Else
                MessageBox.Show("One or more text fields has an invalid input.")
            End If
    So in the end, I wound up not even using the fciain variable nor the name variable.
    Last edited by dday9; Nov 14th, 2013 at 11:09 AM. Reason: When I added font color, it messed up the code tags. So I fixed it.
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  21. #21

    Thread Starter
    New Member
    Join Date
    Nov 2013
    Posts
    14

    Re: I need help with creating a payroll in visual basic

    thanks, I did this but still the calculate button wont work..

  22. #22
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,760

    Re: I need help with creating a payroll in visual basic

    Ok, so what have you tried to fix it?
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  23. #23

    Thread Starter
    New Member
    Join Date
    Nov 2013
    Posts
    14

    Re: I need help with creating a payroll in visual basic

    the 1stOutput is meant to show the calculations but its not showing anything.. how can i create a code for the 1stOutPut. This is the listbox where all calculations is meant to be happening
    Last edited by Tee Baby; Nov 14th, 2013 at 02:54 PM.

  24. #24

    Thread Starter
    New Member
    Join Date
    Nov 2013
    Posts
    14

    Re: I need help with creating a payroll in visual basic

    I just created this and I added it too it.
    lblOutput.Items.Add("Employee Name" + "Gross Pay State Income Tax" + "Federal Income Tax" + "FICA Net Pay"

  25. #25
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,760

    Re: I need help with creating a payroll in visual basic

    I think at this point, it's painfully obvious that you don't have a good understanding of the basics. Before I'm going to help you out any more, I suggest that you look at: http://homeandlearn.co.uk/NET/vbNet.html
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  26. #26

    Thread Starter
    New Member
    Join Date
    Nov 2013
    Posts
    14

    Re: I need help with creating a payroll in visual basic

    alright thanks for your help and have a nice day

  27. #27
    Addicted Member
    Join Date
    Oct 2013
    Posts
    212

    Re: I need help with creating a payroll in visual basic

    This is how you must perform calculations.
    Also I provided a solution how to put them in listbox.

    vb.net Code:
    1. [Private Sub btnCalc(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalc.Click
    2.  
    3.         Dim Message As String = "The withholdings are too great. "
    4.  
    5.         Dim hoursWorked As Decimal
    6.         Dim federalTax As Decimal
    7.         Dim hoursPayRate As Decimal
    8.         Dim stateTax As Decimal
    9.         Dim ficaTax As Decimal
    10.         Dim federalTaxAmount As Decimal
    11.         Dim stateTaxAmount As Decimal
    12.         Dim ficaTaxAmount As Decimal
    13.         Dim grossPay As Decimal
    14.         Dim totalTax As Decimal
    15.         Dim netPay As Decimal
    16.  
    17.  
    18.  
    19.         Decimal.TryParse(txtHoursWorked.Text, hoursWorked)
    20.         Decimal.TryParse(txtFederalTax.Text, federalTax)
    21.         Decimal.TryParse(txtHoursRate.Text, hoursPayRate)
    22.         Decimal.TryParse(txtStateTax.Text, stateTax)
    23.         Decimal.TryParse(txtFica.Text, ficaTax)
    24.  
    25.         federalTax = federalTax / 100
    26.         stateTax = stateTax / 100
    27.         ficaTax = ficaTax / 100
    28.  
    29.  
    30.         grossPay = hoursWorked * hoursPayRate
    31.         federalTaxAmount = grossPay * federalTax
    32.         stateTaxAmount = grossPay * stateTax
    33.         ficaTaxAmount = grossPay * ficaTax
    34.         totalTax = federalTaxAmount + stateTaxAmount + ficaTaxAmount
    35.  
    36.         If totalTax > grossPay Then
    37.             MessageBox.Show(Message, "Payroll information", MessageBoxButtons.OK, MessageBoxIcon.Information)
    38.             Exit Sub
    39.         Else
    40.             netPay = grossPay - totalTax
    41.  
    42.            lstOutput.Items.Add("Gross pay: " & grossPay.ToString("N2").PadLeft(20))
    43.             lstOutput.Items.Add("Federal income tax: " & federalTaxAmount.ToString("N2").PadLeft(15))
    44.             lstOutput.Items.Add("State income tax: " & stateTaxAmount.ToString("N2").PadLeft(15))
    45.             lstOutput.Items.Add("Fica withholdings tax: " & ficaTaxAmount.ToString("N2").PqdLeft(15))
    46.             lstOutput.Items.Add("Net pay: " & netPay.ToString("N2").PadLeft(15))
    47.         End If
    48.  
    49.     End Sub

    Before, I couldn't wrap code until I saw a post of Jmcilhinney, thanks to him.
    Last edited by Atenk; Nov 14th, 2013 at 05:13 PM. Reason: Edit

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