Example 1: Calculator VB.NET Code - TOP10

Example 1: Calculator VB.NET Code

Example 1. How to create calculator by vb.net




Source Code :

Public Class Form1
    Dim sign
    Dim Result As Decimal
    Dim eql

    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bt0.Click
        If eql = "=" Then
            TextBox1.Clear()
            TextBox1.Text = Convert.ToDecimal(TextBox1.Text + bt0.Text).ToString()
        Else
            TextBox1.Text = Convert.ToDecimal(TextBox1.Text + bt0.Text).ToString()
        End If
        eql = ""
    End Sub

    Private Sub bt1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bt1.Click
        If eql = "=" Then
            TextBox1.Clear()
            TextBox1.Text = Convert.ToDecimal(TextBox1.Text + bt1.Text).ToString()
        Else
            TextBox1.Text = Convert.ToDecimal(TextBox1.Text + bt1.Text).ToString()
        End If
        eql = ""
    End Sub

    Private Sub bt2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bt2.Click
        If eql = "=" Then
            TextBox1.Clear()
            TextBox1.Text = Convert.ToDecimal(TextBox1.Text + bt2.Text).ToString()
        Else
            TextBox1.Text = Convert.ToDecimal(TextBox1.Text + bt2.Text).ToString()
        End If
        eql = ""
    End Sub

    Private Sub bt3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bt3.Click
        If eql = "=" Then
            TextBox1.Clear()
            TextBox1.Text = Convert.ToDecimal(TextBox1.Text + bt3.Text).ToString()
        Else
            TextBox1.Text = Convert.ToDecimal(TextBox1.Text + bt3.Text).ToString()
        End If
        eql = ""
    End Sub

    Private Sub bt4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bt4.Click
        If eql = "=" Then
            TextBox1.Clear()
            TextBox1.Text = Convert.ToDecimal(TextBox1.Text + bt4.Text).ToString()
        Else
            TextBox1.Text = Convert.ToDecimal(TextBox1.Text + bt4.Text).ToString()
        End If
        eql = ""
    End Sub

    Private Sub bt5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bt5.Click
        If eql = "=" Then
            TextBox1.Clear()
            TextBox1.Text = Convert.ToDecimal(TextBox1.Text + bt5.Text).ToString()
        Else
            TextBox1.Text = Convert.ToDecimal(TextBox1.Text + bt5.Text).ToString()
        End If
        eql = ""
    End Sub

    Private Sub bt6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bt6.Click
        If eql = "=" Then
            TextBox1.Clear()
            TextBox1.Text = Convert.ToDecimal(TextBox1.Text + bt6.Text).ToString()
        Else
            TextBox1.Text = Convert.ToDecimal(TextBox1.Text + bt6.Text).ToString()
        End If
        eql = ""
    End Sub

    Private Sub bt7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bt7.Click
        If eql = "=" Then
            TextBox1.Clear()
            TextBox1.Text = Convert.ToDecimal(TextBox1.Text + bt7.Text).ToString()
        Else
            TextBox1.Text = Convert.ToDecimal(TextBox1.Text + bt7.Text).ToString()
        End If
        eql = ""
    End Sub

    Private Sub bt8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bt8.Click
        If eql = "=" Then
            TextBox1.Clear()
            TextBox1.Text = Convert.ToDecimal(TextBox1.Text + bt8.Text).ToString()
        Else
            TextBox1.Text = Convert.ToDecimal(TextBox1.Text + bt8.Text).ToString()
        End If
        eql = ""
    End Sub

    Private Sub bt9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bt9.Click
        If eql = "=" Then
            TextBox1.Clear()
            TextBox1.Text = Convert.ToDecimal(TextBox1.Text + bt9.Text).ToString()
        Else
            TextBox1.Text = Convert.ToDecimal(TextBox1.Text + bt9.Text).ToString()
        End If
        eql = ""
    End Sub

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

    Private Sub btsum_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btsum.Click
        Result = Convert.ToDecimal(TextBox1.Text)
        sign = "+"
        TextBox1.Clear()
    End Sub

    Private Sub btsub_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btsub.Click
        Result = Convert.ToDecimal(TextBox1.Text)
        sign = "-"
        TextBox1.Clear()
    End Sub

    Private Sub btmult_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btmult.Click
        Result = Convert.ToDecimal(TextBox1.Text)
        sign = "*"
        TextBox1.Clear()
    End Sub

    Private Sub btdev_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btdev.Click
        Result = Convert.ToDecimal(TextBox1.Text)
        sign = "/"
        TextBox1.Clear()
    End Sub

    Private Sub bteql_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bteql.Click
        eql = "="
        If sign = "+" Then
            TextBox1.Text = (Result + Convert.ToDecimal(TextBox1.Text)).ToString()
        ElseIf sign = "-" Then
            TextBox1.Text = (Result - Convert.ToDecimal(TextBox1.Text)).ToString()
        ElseIf sign = "*" Then
            TextBox1.Text = (Result * Convert.ToDecimal(TextBox1.Text)).ToString()
        ElseIf sign = "/" Then
            TextBox1.Text = (Result / Convert.ToDecimal(TextBox1.Text)).ToString()
        End If
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btdot.Click
        TextBox1.Text = TextBox1.Text + "."
    End Sub
End Class










Previous
Next Post »