Link to home
Start Free TrialLog in
Avatar of chadreeves1
chadreeves1

asked on

Calculating values

Hello everyone,

I am just starting out in Visual Basic .net and was working on a calculator. I have it so that when you click 1 it puts 1 in the text box and so forth. When you click the + button it does this "741" -> "741 + " and then when I add the numbers up it works. however if I then clear the form and add another set of numbers the computer still adds the previuse numbers in as well. How do I fix this? Most of the code is below.

    Dim action As String = ""
    Dim nums As Array
    Dim temp As Integer
    Dim dec As Boolean

    Private Sub btn_zero_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_zero.Click
        result.Text += "0"
    End Sub

    Private Sub btn_pls_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_pls.Click
        action = "+"
        result.Text += " + "
    End Sub

    Private Sub btn_eql_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_eql.Click
        If action.Length > 0 Then
            If action = "+" Then
                nums = result.Text.Split("+")
                Dim i As Integer
                For i = 0 To nums.Length - 1
                    Trim(nums(i))
                    temp = temp + CInt(nums(i))
                    nums(i) = 0
                Next
                result.Text = temp.ToString
                action = ""
            End If
            If action = "-" Then
                nums = result.Text.Split("-")
                Dim i As Integer
                Trim(nums(i))
                temp = CInt(nums(0)) - CInt(nums(1))
                If nums(0) > nums(1) Then
                    result.Text = "-" & temp.ToString
                Else
                    result.Text = temp.ToString
                End If
                action = ""
            End If
        Else
            MsgBox("Please select an action.", MsgBoxStyle.OKOnly)
        End If
    End Sub

    Private Sub btn_one_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_one.Click
        result.Text += "1"
    End Sub

    Private Sub btn_two_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_two.Click
        result.Text += "2"
    End Sub

    Private Sub btn_dbl_zero_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_dbl_zero.Click
        result.Text += "00"
    End Sub

    Private Sub btn_three_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_three.Click
        result.Text += "3"
    End Sub

    Private Sub btn_six_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_six.Click
        result.Text += "6"
    End Sub

    Private Sub btn_five_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_five.Click
        result.Text += "5"
    End Sub

    Private Sub btn_four_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_four.Click
        result.Text += "4"
    End Sub

    Private Sub btn_seven_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_seven.Click
        result.Text += "7"
    End Sub

    Private Sub btn_eight_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_eight.Click
        result.Text += "8"
    End Sub

    Private Sub btn_nine_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_nine.Click
        result.Text += "9"
    End Sub

    Private Sub btn_clr_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_clr.Click
        result.Text = ""
        action = ""
    End Sub

    Private Sub btn_sub_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_sub.Click
        action = "-"
        result.Text += " - "
    End Sub

    Private Sub btn_sqr_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_sqr.Click
        If action.Length > 0 Then
            MsgBox("You have already selected an action, you may not select an action and square at the same time. Please clear the results and try again.", MsgBoxStyle.OKOnly)
        Else
            result.Text = CInt(result.Text) * CInt(result.Text)
            action = ""
        End If
    End Sub

Thank you,
chadreeves1
ASKER CERTIFIED SOLUTION
Avatar of RonaldBiemans
RonaldBiemans

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of chadreeves1
chadreeves1

ASKER

Duh,

I dont know y i didn't see that.

Thank you,
RonaldBiemans