8 Replies - 1640 Views - Last Post: 21 April 2013 - 03:03 PM Rate Topic: -----

#1 verrillo  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 21-April 13

Payroll calculator compounding problem

Posted 21 April 2013 - 12:01 PM

Hello,
I noticed there are a ton of other payroll calculator problems, but mine seems a bit different. In this program the output should be displayed in two ways (a message box, which works) and to the textboxes on the right (I have attached a screenshot of the interface). I have no problem getting the output to the textboxes, however you should be able to enter numerous users. So the numbers have to remain there, then have the new numbers added to them. That is where I hit the problem. This is what I have so far, any help would be appreciated!
Public Class frmSunriseCreditUnionPayroll
    Dim decHourlyWage As Decimal = 0D
    Dim intBaseHoursWorked As Integer = 0
    Dim intTotalHoursWorked As Integer = 0
    Dim decOvertimeRate As Decimal = 0D
    Dim intBaseTotalWorkHours As Integer = 0
    Dim decRegularPay As Decimal = 0D
    Dim decOvertimePay As Decimal = 0D
    Dim decGrossPay As Decimal = 0D

   

    Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click
        'Get and store user input, conversions are necessary
        Dim currentregHours As Integer = 0
        Dim currentovertimeHoursWorked As Integer = 0
        Dim currentaverageOvertimeHours As Integer = 0
        Dim currenttotalOvertimePay As Decimal = 0D
        Dim currenttotalRegPay As Decimal = 0D
        Dim currenttotalGrossPay As Decimal = 0D

        currentregHours = CInt(txtHoursWorked.Text)
        currentovertimeHoursWorked = CInt(txtTotalOvertimeHoursWorked.Text)
        currentaverageOvertimeHours = CInt(txtAverageOvertimePay.Text)
        currenttotalOvertimePay = CDec(txtTotalOvertimePay.Text)
        currenttotalRegPay = CDec(txtRegularPay.Text)
        currenttotalGrossPay = CDec(txtGrossPay.Text)

        Call Me.test(regHours:=)

        txtRegularHours.Text = txtHoursWorked.Text + txtRegularHours.Text

        Try
            If IsValidData() Then

                decHourlyWage = CDec(txtHourlyWage.Text)
                intBaseHoursWorked = CInt(txtHoursWorked.Text)
                intBaseTotalWorkHours = CInt(txtBaseWorkHours.Text)
                decOvertimeRate = CDec(txtOvertimeRate.Text)

                'Calculate regular pay = wage * hours
                decRegularPay = decHourlyWage * intBaseHoursWorked

                'Determine if over base work hours
                'If it is, then mulitply by overtime rate
                If intBaseHoursWorked > intBaseTotalWorkHours Then
                    decOvertimePay = ((intBaseHoursWorked - intBaseTotalWorkHours) * decHourlyWage) * decOvertimeRate
                End If

                'Calculate gross pay = regular pay + overtime pay
                decGrossPay = decRegularPay + decOvertimePay

                'Call fillTextBoxes Sub Procedure
                Call fillTextBoxes()

                'Call messageSummary Sub Procedure
                Call messageSummary()
            End If
        Catch ex As Exception
            MessageBox.Show(ex.Message & vbCrLf & vbCrLf &
                            ex.GetType.ToString & vbCrLf & vbCrLf &
                            ex.StackTrace, "Exception")
        End Try

    End Sub
    Private Sub fillTextBoxes()
        'This fills the appropriate text boxes with the data
        'It also performs necessary calculations
        txtRegularHours.Text = CStr(intBaseHoursWorked)
        txtTotalOvertimeHoursWorked.Text = CStr((intBaseHoursWorked - intBaseTotalWorkHours))
        txtTotalOvertimePay.Text = CStr((((intBaseHoursWorked - intBaseTotalWorkHours) * decHourlyWage) * decOvertimeRate))
        txtRegularPay.Text = CStr(decHourlyWage * intBaseHoursWorked)
        txtGrossPay.Text = CStr(decRegularPay + decOvertimePay)
    End Sub



Is This A Good Question/Topic? 0
  • +

Replies To: Payroll calculator compounding problem

#2 andrewsw  Icon User is offline

  • blow up my boots
  • member icon

Reputation: 6500
  • View blog
  • Posts: 26,286
  • Joined: 12-December 12

Re: Payroll calculator compounding problem

Posted 21 April 2013 - 12:47 PM

What have you attempted?

The process could be:

Get the text from a textbox;
Convert this text to a number (first checking if this is possible);
Add to this number;
Set the text of the textbox to this new number, converted to a string.
Was This Post Helpful? 0
  • +
  • -

#3 verrillo  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 21-April 13

Re: Payroll calculator compounding problem

Posted 21 April 2013 - 02:12 PM

I feel like I have tried a ton of things, but the logic is killing me. I think what I am working with is something like this (since subs and event headers cant be more than 10 lines of code for this class) A variable outside the main sub which I can call. A variable in the main sub which holds the current user data. And then a method which takes the value, plus the current value in the textbox.

I just do not know how to get it into code, I need some help.
Was This Post Helpful? 0
  • +
  • -

#4 andrewsw  Icon User is offline

  • blow up my boots
  • member icon

Reputation: 6500
  • View blog
  • Posts: 26,286
  • Joined: 12-December 12

Re: Payroll calculator compounding problem

Posted 21 April 2013 - 02:29 PM

View Postverrillo, on 21 April 2013 - 09:12 PM, said:

I feel like I have tried a ton of things, but the logic is killing me. I think what I am working with is something like this (since subs and event headers cant be more than 10 lines of code for this class) A variable outside the main sub which I can call. A variable in the main sub which holds the current user data. And then a method which takes the value, plus the current value in the textbox.

I just do not know how to get it into code, I need some help.

This confuses me. I read from your first post that you just wanted to edit the textboxes, but obviously not.

Do you want to save a single value each time, or a set of values? If a single value then you could use a List. Declare it at the top of your class, and then Add() to this list.

If you want to save a set of values each time, then you might create a separate Class to store these values, and a List to maintain the different sets of values.

Quote

I feel like I have tried a ton of things

Erm, what did you try? (Your code gives no indication.)

This post has been edited by andrewsw: 21 April 2013 - 02:30 PM

Was This Post Helpful? 0
  • +
  • -

#5 verrillo  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 21-April 13

Re: Payroll calculator compounding problem

Posted 21 April 2013 - 02:41 PM

It is kind of hard to explain.. but if you can see the image of my interface I may be able to explain it.

A user enters data on the left, then they press Calculate. The data is then thrown to the textboxes on the right. I want to be able to enter another set of data on the left, Press Calculate, and then the data will be added on to the current data on the right.

Attached image(s)

  • Attached Image

Was This Post Helpful? 0
  • +
  • -

#6 andrewsw  Icon User is offline

  • blow up my boots
  • member icon

Reputation: 6500
  • View blog
  • Posts: 26,286
  • Joined: 12-December 12

Re: Payroll calculator compounding problem

Posted 21 April 2013 - 02:49 PM

Yes, that is the process that I described in my first post. (The objects on the right are labels rather than textboxes, but you still modify their Text property.)

If you don't know how to translate my outline into code then I suggest that you need to start-over. That is, study the fundamentals of VB: working with variables, using functions, etc. There are tutorials here @DIC.

This post has been edited by andrewsw: 21 April 2013 - 02:52 PM

Was This Post Helpful? 0
  • +
  • -

#7 verrillo  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 21-April 13

Re: Payroll calculator compounding problem

Posted 21 April 2013 - 02:56 PM

No, I completely grasp your outline. The problem I am having is getting this all to occur on the second Calculate click
Was This Post Helpful? 0
  • +
  • -

#8 andrewsw  Icon User is offline

  • blow up my boots
  • member icon

Reputation: 6500
  • View blog
  • Posts: 26,286
  • Joined: 12-December 12

Re: Payroll calculator compounding problem

Posted 21 April 2013 - 03:01 PM

View Postverrillo, on 21 April 2013 - 09:56 PM, said:

No, I completely grasp your outline. The problem I am having is getting this all to occur on the second Calculate click

I would use an if statement to check if the first box on the right is empty (or contains whatever text you might use as a default). If it is empty, then this is the first run, so fill the boxes with the current values. If it is not empty, then you know that you need to add to the values.
Was This Post Helpful? 0
  • +
  • -

#9 verrillo  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 21-April 13

Re: Payroll calculator compounding problem

Posted 21 April 2013 - 03:03 PM

Thank you, I will give this a shot
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1