I have designed a simple calculator (website application) using asp.net web forms

This is my code for it and it works fine

    Protected Sub btnAdd_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnAdd.Click
        If IsNumeric(txtFirstNumber.Text) = False OrElse IsNumeric(txtSecondNumber.Text) = False Then
            lblResult.Text = "Enter A Number"
        Else
            Dim first As Decimal
            Dim second As Decimal
            Dim output As Decimal
            first = Convert.ToDecimal(txtFirstNumber.Text)
            second = Convert.ToDecimal(txtSecondNumber.Text)
            output = first + second
            lblResult.Text = (output.ToString())
        End If
    End Sub
    Protected Sub btnSubtract_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubtract.Click
        If IsNumeric(txtFirstNumber.Text) = False OrElse IsNumeric(txtSecondNumber.Text) = False Then
            lblResult.Text = "Enter A Number"
        Else
            Dim first As Decimal
            Dim second As Decimal
            Dim output As Decimal
            first = Convert.ToDecimal(txtFirstNumber.Text)
            second = Convert.ToDecimal(txtSecondNumber.Text)
            output = first - second
            lblResult.Text = (output.ToString())

        End If

    End Sub
    Protected Sub btnDivide_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnDivide.Click
        If IsNumeric(txtFirstNumber.Text) = False OrElse IsNumeric(txtSecondNumber.Text) = False Then
            lblResult.Text = "Enter A Number"
        Else
            Dim first As Decimal
            Dim second As Decimal
            Dim output As Decimal
            first = Convert.ToDecimal(txtFirstNumber.Text)
            second = Convert.ToDecimal(txtSecondNumber.Text)

            If first > 0 AndAlso second > 0 Then
                output = first / second
                lblResult.Text = (output.ToString())
            Else
                lblResult.Text = "Division by 0 not allowed"
            End If

        End If
    End Sub
    Protected Sub btnMultiply_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnMultiply.Click
        If IsNumeric(txtFirstNumber.Text) = False OrElse IsNumeric(txtSecondNumber.Text) = False Then
            lblResult.Text = "Enter A Number"
        Else
            Dim first As Decimal
            Dim second As Decimal
            Dim output As Decimal
            first = Convert.ToDecimal(txtFirstNumber.Text)
            second = Convert.ToDecimal(txtSecondNumber.Text)
            output = first * second
            lblResult.Text = (output.ToString())

        End If
    End Sub
    Protected Sub btnClear_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnClear.Click
        Clear()
    End Sub

    Private Sub Clear()
        txtFirstNumber.Text = ""
        txtSecondNumber.Text = ""
        lblResult.Text = ""
    End Sub
End Class

What I need help with is, how do I modify code behind file and can only define one subroutine to handle all of the button events

Related posts

Recent Viewed