All pastes #466675 Raw Edit

Calculator

public text v1 · immutable
·published 2007-05-01 03:24 UTC
rendered paste body
Public Class Calc
    Dim buffOne, buffTwo, finalbuf As Integer
    Dim op, lastop As String
    Dim top, num2 As Boolean



    Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
        txtInt.Text = ""
        buffOne = 0
        op = ""
    End Sub

    Private Sub docalc(ByVal num As String)
        If op = "" Then
            txtInt.Text = txtInt.Text & num
        ElseIf op = "clear" Then
            txtInt.Text = num
        Else
            txtInt.Text = num
            lastop = op
            op = ""
        End If

    End Sub

    Private Sub btn0_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn0.Click
        docalc("0")
    End Sub

    Private Sub btn1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn1.Click
        docalc("1")
    End Sub

    Private Sub btn2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn2.Click
        docalc("2")
    End Sub

    Private Sub btn3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn3.Click
        docalc("3")
    End Sub

    Private Sub btn4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn4.Click
        docalc("4")
    End Sub

    Private Sub btn5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn5.Click
        docalc("5")
    End Sub

    Private Sub btn6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn6.Click
        docalc("6")
    End Sub

    Private Sub btn7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn7.Click
        docalc("7")
    End Sub

    Private Sub btn8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn8.Click
        docalc("8")
    End Sub

    Private Sub btn9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn9.Click
        docalc("9")
    End Sub

    Private Sub btnPlus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPlus.Click
        Dim plusbuf As Integer
        plusbuf = txtInt.Text + buffOne
        buffOne = plusbuf
        txtInt.Text = plusbuf
        op = "+"
        top = True
    End Sub

    Private Sub btnMinus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMinus.Click
        Dim minusbuf As Integer
        minusbuf = txtInt.Text - buffOne
        buffOne = minusbuf
        txtInt.Text = minusbuf
        op = "-"
        top = True
    End Sub

    Private Sub btnMult_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMult.Click
        Dim multbuf As Integer
        If buffOne = 0 Then
            buffOne = 1
        End If
        multbuf = txtInt.Text * buffOne
        buffOne = multbuf
        txtInt.Text = multbuf
        op = "*"
        top = True
    End Sub

    Private Sub btnDiv_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDiv.Click
        Dim divbuf As Integer
        If buffOne = 0 Then
            buffOne = 1
        End If
        divbuf = txtInt.Text / buffOne
        buffOne = divbuf
        txtInt.Text = divbuf
        op = "/"
        top = True
    End Sub

    Private Sub btnEnter_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEnter.Click
        Select Case lastop
            Case "+" : finalbuf = buffOne + txtInt.Text
            Case "-" : finalbuf = buffOne - txtInt.Text
            Case "*" : finalbuf = buffOne * txtInt.Text
            Case "/" : finalbuf = buffOne / txtInt.Text
        End Select

        txtInt.Text = finalbuf

        buffOne = 0
        op = "+"
        lastop = ""

    End Sub


End Class