0

While executing the following code and when clicking the clear button it gives me error "Error Input String in not correct" line --> workedHour = Decimal.Parse(HourWorkedTextBox.Text) Any help will be highly appreciated

Public Class Payroll
    Dim fullName As String
    Dim pay_Rate, workedHour, grossPay, netPay, taxRate As Decimal
    Dim taxAmount As Integer

    Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LabelName.Click

    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub

    Private Sub NameTextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NameTextBox.TextChanged
    End Sub

    Private Sub ButtonClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonClear.Click

        NameTextBox.Clear()
        With HourWorkedTextBox
            with PayRate
            .Clear()
            .Focus()
            End With
        End With
        SingleCheckBox.Checked = False
        FamilyCheckBox.Checked = False
        DisplayName.Visible = False
        DisplayGrossPay.Visible = False
        DisplayTaxAmount.Visible = False
        DisplayNetPay.Visible = False
    End Sub

    Private Sub HourWorkedTextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles HourWorkedTextBox.TextChanged
        workedHour = Decimal.Parse(HourWorkedTextBox.Text)
    End Sub

    Private Sub PayRate_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PayRate.TextChanged
        pay_Rate = Decimal.Parse(PayRate.Text)
    End Sub

    Private Sub SingleCheckBox_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SingleCheckBox.CheckedChanged

    End Sub

    Private Sub ButtonCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonCalculate.Click
        If NameTextBox.Text = String.Empty Then
            MsgBox("Please Enter Full Name")
            Return
        ElseIf IsNumeric(NameTextBox.Text) Then
            MsgBox("Invalid input for name, please enter valid input")
        ElseIf (HourWorkedTextBox.Text = "") Then
            MsgBox("Worked hours Can't be empty")
        ElseIf (workedHour < 5 Or workedHour > 60) Then
            MsgBox("Worked hours can't be less than 5 and more than 60, please provide the worked hours")
        ElseIf PayRate.Text = "" Then
            MsgBox("Pay rate Can't be empty, please provide the pay rate")
        ElseIf (pay_Rate < 8.0 Or pay_Rate > 40.0) Then
            MsgBox("Pay rate can't be less than $8.0 and more than $40.0")
        ElseIf SingleCheckBox.Checked Then
            taxRate = 0.18
        ElseIf FamilyCheckBox.Checked Then
            taxRate = 0.15
        ElseIf (SingleCheckBox.Checked = False And FamilyCheckBox.Checked = False) Then
            MsgBox("Please check the appropriate tax rate")
        End If
        MsgBox("Payroll Calculated Successfully, click display button to view your pay stub")
    End Sub

    Private Sub DisplayName_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DisplayName.Click

    End Sub

    Private Sub DisplayGrossPay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DisplayGrossPay.Click

    End Sub

    Private Sub DisplayTaxAmount_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DisplayTaxAmount.Click

    End Sub

    Private Sub DisplayNetPay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DisplayNetPay.Click

    End Sub

    Private Sub ButtonExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonExit.Click
        Me.Close()
    End Sub

    Private Sub FamilyCheckBox_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FamilyCheckBox.CheckedChanged

    End Sub

    Private Sub ButtonDisplay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonDisplay.Click

        DisplayName.Text = NameTextBox.Text
        grossPay = workedHour * pay_Rate
        DisplayGrossPay.Text = (grossPay.ToString("$0.00"))
        taxAmount = grossPay * taxRate
        DisplayTaxAmount.Text = (taxAmount.ToString("$0.00"))
        netPay = grossPay - taxAmount
        DisplayNetPay.Text = (netPay.ToString("$0.00"))
        GroupBoxPayroll.Enabled = True
        GroupBoxPayroll.Visible = True

    End Sub
End Class
2
Contributors
1
Reply
2
Views
5 Years
Discussion Span
Last Post by AndreRet
0

The value returned by HourWorkedTextBox.Text is not an integer. It seems you are returning something between 5 and 60, which is an integer. the textbox is returning something else...

Edited by AndreRet

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.