Can Someone Help Me With Visual Basic Chapter 4 Payroll?

ylime 21 Reputation points
2020-12-08T14:19:43.357+00:00

I'm doing code in computer class and we're working on exercises. This exercise is called Payroll and I'm having trouble with it. Every time I try to test, I press the "Pay" button and the numbers reset. Can someone look at my code and help me? I know I did something wrong.

Public Class Form1
Private Sub btnPay_Click(sender As Object, e As EventArgs) Handles btnPay.Click

    Dim HoursWorked As Double
    Dim HourlyRate As Double
    Dim Pay As Double
    Dim OvertimeRate As Double

    Me.txtHoursWorked.Text = HoursWorked
    Me.txtHourlyRate.Text = HourlyRate

    If HoursWorked <= 40 Then
        Pay = HoursWorked * HourlyRate
    Else
        OvertimeRate = HourlyRate * 1.5
        Pay = (HoursWorked - 40) * 10 * 1.5
    End If

    If radNo.Checked Then
        Pay = Pay * 0.18
    Else
        MessageBox.Show("No Taxes Deducted")
    End If

    Me.lblAnswer.Text = "$" & Pay

End Sub

End Class

Visual Studio
Visual Studio
A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.
4,647 questions
Visual Studio Debugging
Visual Studio Debugging
Visual Studio: A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.Debugging: The act or process of detecting, locating, and correcting logical or syntactical errors in a program or malfunctions in hardware. In hardware contexts, the term troubleshoot is the term more frequently used, especially if the problem is major.
947 questions
Visual Studio Testing
Visual Studio Testing
Visual Studio: A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.Testing: The act or process of applying tests as a means of analysis or diagnosis.
329 questions
0 comments No comments
{count} votes

Accepted answer
  1. Viorel 112.7K Reputation points
    2020-12-08T14:23:27.497+00:00

    Maybe you should replace

    Me.txtHoursWorked.Text = HoursWorked
    Me.txtHourlyRate.Text = HourlyRate
    

    with

    HoursWorked = CDbl(Me.txtHoursWorked.Text)
    HourlyRate = CDbl(Me.txtHourlyRate.Text)
    
    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful