Calculator in VB.net

CODE : 

Public Class Form1
    Public ans As Single
    Private sign As String

    Private Sub btn1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn1.Click, btn0.Click, btn2.Click, btn3.Click, btn4.Click, btn5.Click, btn6.Click, btn7.Click, btn8.Click, btn9.Click, btnpnt.Click
        txtnumber.Text += sender.text
    End Sub

    Private Sub btnequal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnequal.Click
        If sign = "+" Then
            ans = ans + Val(txtnumber.Text)
            txtnumber.Text = ans.ToString
        ElseIf sign = "-" Then
            ans = ans - Val(txtnumber.Text)
            txtnumber.Text = ans.ToString
        ElseIf sign = "*" Then
            ans = ans * Val(txtnumber.Text)
            txtnumber.Text = ans.ToString
        ElseIf sign = "/" Then
            ans = ans / Val(txtnumber.Text)
            txtnumber.Text = ans.ToString
        ElseIf sign = "%" Then
            ans = ans Mod Val(txtnumber.Text)
            txtnumber.Text = ans.ToString
            End If
    End Sub

    Private Sub btnadd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnadd.Click, btnsub.Click, btnmul.Click, btndiv.Click, btnmod.Click
        ans = Val(txtnumber.Text)
        sign = sender.text
        txtnumber.Text = ""
    End Sub

    Private Sub btnclear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnclear.Click
        txtnumber.Text = ""
        ans = 0
        sign = ""
    End Sub

    Private Sub btnback_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnback.Click
        Dim str As String = txtnumber.Text
        If str.Length > 0 Then
            txtnumber.Text = str.Substring(0, str.Length - 1)
        End If
    End Sub
End Class

DOWNLOAD


Calculator in VB.net Calculator in VB.net Reviewed by Unknown on 6:17 pm Rating: 5

No comments: