VB 계산기

5731 단어 VB6.0VB. 네 t
코드의 간략화는 포기하고, 우선 형태만(소수점 없음)의 계산기를 작성.
1부터 스스로 작성했으므로 츳코미는 가득할지도 모릅니다만,,,
Public Class Form1
    Dim anser As Integer
    'null=0, +=1, -=2, *=3, /=4 # =前に何の演算子であったか。
    Dim before As Integer

    Private Sub Form_initialize()
        anser = 0
        before = 0
    End Sub

    Private Sub btnZero_Click(sender As Object, e As EventArgs) Handles btnZero.Click
        If lblAnser.Text = "0" Then
            lblAnser.Text = "0"
        Else
            lblAnser.Text = lblAnser.Text & "0"
        End If
    End Sub

    Private Sub btnOne_Click(sender As Object, e As EventArgs) Handles btnOne.Click
        If lblAnser.Text = "0" Then
            lblAnser.Text = "1"
        Else
            lblAnser.Text = lblAnser.Text & "1"
        End If
    End Sub

    Private Sub btnTwo_Click(sender As Object, e As EventArgs) Handles btnTwo.Click
        If lblAnser.Text = "0" Then
            lblAnser.Text = "2"
        Else
            lblAnser.Text = lblAnser.Text & "2"
        End If
    End Sub

    Private Sub btnThree_Click(sender As Object, e As EventArgs) Handles btnThree.Click
        If lblAnser.Text = "0" Then
            lblAnser.Text = "3"
        Else
            lblAnser.Text = lblAnser.Text & "3"
        End If
    End Sub

    Private Sub btnFour_Click(sender As Object, e As EventArgs) Handles btnFour.Click
        If lblAnser.Text = "0" Then
            lblAnser.Text = "4"
        Else
            lblAnser.Text = lblAnser.Text & "4"
        End If
    End Sub

    Private Sub btnFive_Click(sender As Object, e As EventArgs) Handles btnFive.Click
        If lblAnser.Text = "0" Then
            lblAnser.Text = "5"
        Else
            lblAnser.Text = lblAnser.Text & "5"
        End If
    End Sub

    Private Sub btnSix_Click(sender As Object, e As EventArgs) Handles btnSix.Click
        If lblAnser.Text = "0" Then
            lblAnser.Text = "6"
        Else
            lblAnser.Text = lblAnser.Text & "6"
        End If
    End Sub

    Private Sub btnSeven_Click(sender As Object, e As EventArgs) Handles btnSeven.Click
        If lblAnser.Text = "0" Then
            lblAnser.Text = "7"
        Else
            lblAnser.Text = lblAnser.Text & "7"
        End If
    End Sub

    Private Sub btnEight_Click(sender As Object, e As EventArgs) Handles btnEight.Click
        If lblAnser.Text = "0" Then
            lblAnser.Text = "8"
        Else
            lblAnser.Text = lblAnser.Text & "8"
        End If
    End Sub

    Private Sub btnNine_Click(sender As Object, e As EventArgs) Handles btnNine.Click
        If lblAnser.Text = "0" Then
            lblAnser.Text = "9"
        Else
            lblAnser.Text = lblAnser.Text & "9"
        End If
    End Sub

    Private Sub btnAdd_Click(sender As Object, e As EventArgs) Handles btnAdd.Click
        Dim num As Integer = Integer.Parse(lblAnser.Text)
        If anser = 0 Then
            anser = lblAnser.Text
            lblAnser.Text = 0
        Else
            anser = anser + lblAnser.Text
            lblAnser.Text = 0
        End If
        before = 1
    End Sub


    Private Sub btnDif_Click(sender As Object, e As EventArgs) Handles btnDif.Click
        Dim num As Integer = Integer.Parse(lblAnser.Text)
        If anser = 0 Then
            anser = lblAnser.Text
            lblAnser.Text = 0
        Else
            anser = anser - lblAnser.Text
            lblAnser.Text = 0
        End If
        before = 2
    End Sub


    Private Sub btnPro_Click(sender As Object, e As EventArgs) Handles btnPro.Click
        Dim num As Integer = Integer.Parse(lblAnser.Text)
        If anser = 0 Then
            anser = lblAnser.Text
            lblAnser.Text = 0
        Else
            anser = anser * lblAnser.Text
            lblAnser.Text = 0
        End If
        before = 3
    End Sub

    Private Sub btnQuo_Click(sender As Object, e As EventArgs) Handles btnQuo.Click
        Dim num As Integer = Integer.Parse(lblAnser.Text)
        If anser = 0 Then
            anser = lblAnser.Text
            lblAnser.Text = 0
        Else
            anser = anser / lblAnser.Text
            lblAnser.Text = 0
        End If
        before = 4
    End Sub


    Private Sub btnResult_Click(sender As Object, e As EventArgs) Handles btnResult.Click
        If before = 1 Then
            anser = anser + lblAnser.Text
        ElseIf before = 2 Then
            anser = anser - lblAnser.Text
        ElseIf before = 3 Then
            anser = anser * lblAnser.Text
        ElseIf before = 4 Then
            anser = anser / lblAnser.Text
        End If
        lblAnser.Text = 0
        MessageBox.Show(anser)
        anser = 0
    End Sub

End Class






뭐 뭐 모양이 되고 있다…

좋은 웹페이지 즐겨찾기