Sunday, 22 June 2014

Simple calculator made in the vb.net for beginners


Simple calculator made in the visual basic for beginners:

Everybody who knows the programming is wanted to create the calculator. This simple source code will create the simple calculator for the windows in the vb.net programming.
 

 Create the new windows form application and use the below coding:

Public Class Form1

    Dim a As Double

    Dim s As String

    Public Sub calculate()

        Select Case s

            Case "plus"

                a = a + TextBox1.Text

                TextBox1.Text = Str(a)

            Case "sub"

                a = a - TextBox1.Text

                TextBox1.Text = Str(a)

            Case "mul"

                a = a * TextBox1.Text

                TextBox1.Text = Str(a)

            Case "div"

                a = a / TextBox1.Text

                TextBox1.Text = Str(a)

 

        End Select

    End Sub

 

 

 

 

 

    Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged

 

    End Sub

 

    Private Sub Button15_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button15.Click

        TextBox1.Text &= Button15.Text

    End Sub

 

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

 

    End Sub

 

    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click

        TextBox1.Text &= Button5.Text

 

    End Sub

 

    Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click

        TextBox1.Text &= Button6.Text

    End Sub

 

    Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click

        TextBox1.Text &= Button7.Text

    End Sub

 

    Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click

        TextBox1.Text &= Button8.Text

    End Sub

 

    Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click

        TextBox1.Text &= Button9.Text

    End Sub

 

    Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Click

        TextBox1.Text &= Button10.Text

    End Sub

 

    Private Sub Button11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button11.Click

        TextBox1.Text &= Button11.Text

    End Sub

 

    Private Sub Button12_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button12.Click

        TextBox1.Text &= Button12.Text

    End Sub

 

    Private Sub Button13_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button13.Click

        TextBox1.Text &= Button13.Text

    End Sub

 

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

        If (a > 0) Or (a < 0) Then

            calculate()

        Else

            a = TextBox1.Text

        End If

        s = "plus"

        TextBox1.Text = ""

    End Sub

 

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

        If (a > 0) Or (a < 0) Then

            calculate()

        Else

            a = TextBox1.Text

        End If

        s = "sub"

        TextBox1.Text = ""

    End Sub

 

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click

        If (a > 0) Or (a < 0) Then

            calculate()

        Else

            a = TextBox1.Text

        End If

        s = "mul"

        TextBox1.Text = ""

    End Sub

 

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click

        If (a > 0) Or (a < 0) Then

            calculate()

        Else

            a = TextBox1.Text

        End If

        s = "div"

        TextBox1.Text = ""

    End Sub

 

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

        calculate()

        a = 0

        s = ""

      

    End Sub

 

    Private Sub Button16_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button16.Click

        a = 0

        s = ""

        TextBox1.Text = ""

 

    End Sub

 

    Private Sub Button17_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button17.Click

        TextBox1.Text &= Button17.Text

    End Sub

End Class

 

Explanation:

The above coding is using the very simple logic to calculate. That is every time you enter the values it will verify the s value and  change the calculate() to calculate the values in the textbox.

So enjoy creating windows like calculator.

No comments:

Post a Comment