Hey, i have to finished a cacluator, all my code seems to be working apart from the equals button and i do not understand why..i've tried several different things such as a case too but nothing seems to work to get the equals button working..please help!!
This is my code, no need for all the buttons they are the same and ive declared variables..help soon please!

Private Sub btn0_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn0.Click
    If btnCalculation = 1 Or btnCalculation = 2 Then
        txtDisplay.Clear()
    End If
    txtDisplay.Text = txtDisplay.Text & btn0.Text
End Sub

Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click

    If btnCalculation = 1 Or btnCalculation = 2 Then
        txtDisplay.Clear()
    End If

    txtDisplay.Text = txtDisplay.Text & "+" 
    btnCalculation = 1
    Number1 = txtDisplay.text

End Sub


Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
    If btnClear.Enabled = True Then
        Number1 = 0
        Number2 = 0
        txtDisplay.Text = " "
    End If

End Sub

Private Sub btnMinus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMinus.Click
    Number1 = txtDisplay.Text
    If btnCalculation = 1 Or btnCalculation = 2 Then
        txtDisplay.Clear()
    End If

    txtDisplay.Text = txtDisplay.Text & "-"
    btnCalculation = 2

End Sub

Private Sub btnEnter_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEnter.Click

    Number2 = txtDisplay.Text

    If btnCalculation = 1 Then
        txtDisplay.Text = Number1 + Number2
    ElseIf btnCalculation = 2 Then
        txtDisplay.Text = Number1 - Number2
    End If


End Sub

End Class

Since you've concatenated into txtDisplay.text the minus or plus sign, I don't think that txtDisplay.text is numeric.
With that said, when you are assinging Number2 = txtDisplay.text means that Number2 is not numeric, so you shouldn't be able to add or subtract anything with Number2 as part of the calculation.

After seeing your code again, the same story goes with Number1.
I'm suggesting you either messagebox or debug.print both Number1 & Number2 and see what you are trying to add or subtract.

If my guess is correct, you could assign Number1 = txtDisplay.text before concatenating the plus or minus sign and then use the length of Number 1 (plus 1 char for the plus or minus) to get Number2 out of txtDisplay.text.

Please post project in a ZIP folder
Thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.