Saturday, February 15, 2014

VB.NET code for Simple Calculator

simple-calculator-vbnet-code-smitguide

Public Class Calculator
    Dim first, sec, thrd, ans As Decimal
    Dim sss, tt As Integer

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        TextBox1.Text = (TextBox1.Text) & 1
    End Sub

    Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
        TextBox1.Text = (TextBox1.Text) & 2
    End Sub

    Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
        TextBox1.Text = (TextBox1.Text) & 3
    End Sub

    Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
        TextBox1.Text = (TextBox1.Text) & 4
    End Sub

    Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click
        TextBox1.Text = (TextBox1.Text) & 5
    End Sub

    Private Sub Button7_Click(sender As Object, e As EventArgs) Handles Button7.Click
        TextBox1.Text = (TextBox1.Text) & 6
    End Sub

    Private Sub Button8_Click(sender As Object, e As EventArgs) Handles Button8.Click
        TextBox1.Text = (TextBox1.Text) & 7
    End Sub

    Private Sub Button9_Click(sender As Object, e As EventArgs) Handles Button9.Click
        TextBox1.Text = (TextBox1.Text) & 8
    End Sub

    Private Sub Button10_Click(sender As Object, e As EventArgs) Handles Button10.Click
        TextBox1.Text = (TextBox1.Text) & 9
    End Sub

    Private Sub Button14_Click(sender As Object, e As EventArgs) Handles Button14.Click

        If tt = 0 Then
            first = Val(TextBox1.Text)
            tt = 1
        ElseIf tt = 1 Then
            sec = Val(TextBox1.Text)
        End If
        TextBox1.Clear()
        sss = 1
    End Sub

    Private Sub Button15_Click(sender As Object, e As EventArgs) Handles Button15.Click
        Select Case sss
            Case 1
                thrd = Val(TextBox1.Text)
                ans = (first + sec) + thrd
            Case 2
                sec = Val(TextBox1.Text)
                ans = first - sec
            Case 3
                sec = Val(TextBox1.Text)
                ans = first * sec
            Case 4
                sec = Val(TextBox1.Text)
                ans = first / sec
        End Select

        TextBox1.Text = ans
    End Sub

    Private Sub Button13_Click(sender As Object, e As EventArgs) Handles Button13.Click
        If tt = 0 Then
            first = Val(TextBox1.Text)
            tt = 1
        ElseIf tt = 1 Then
            sec = Val(TextBox1.Text)
        End If
        TextBox1.Clear()
        sss = 2
    End Sub

    Private Sub Button12_Click(sender As Object, e As EventArgs) Handles Button12.Click
        If tt = 0 Then
            first = Val(TextBox1.Text)
            tt = 1
        ElseIf tt = 1 Then
            sec = Val(TextBox1.Text)
        End If
        TextBox1.Clear()
        sss = 3
    End Sub

    Private Sub Button11_Click(sender As Object, e As EventArgs) Handles Button11.Click
        If tt = 0 Then
            first = Val(TextBox1.Text)
            tt = 1
        ElseIf tt = 1 Then
            sec = Val(TextBox1.Text)
        End If
        TextBox1.Clear()
        sss = 4
    End Sub

    Private Sub Calculator_Load(sender As Object, e As EventArgs) Handles MyBase.Load
       
    End Sub

    Private Sub Button16_Click(sender As Object, e As EventArgs) Handles Button16.Click
        Dim axx As Integer

        axx = (TextBox1.Text.Length) - 1

        TextBox1.Text = TextBox1.Text.Substring(0, axx)
    End Sub
End Class

No comments:

Post a Comment