What is wrong with this code of mine?

Private Sub btnPlus_Click()
If counter = 0 Then
savedNumber = Val(txtNumber)
counter = 1
End If

If counter <> 0 Then value = Val(txtNumber)

End Sub
Private Sub btnEquals_Click()
result = Val(savedNumber) + Val(value)
txtNumber.Text = CStr(result)

End Sub
Private Sub btnThree_Click()
txtNumber = txtNumber + "3"
End Sub

Private Sub btnTwo_Click()
txtNumber = txtNumber + "2"
End Sub

When I press the buttons "2", "+", "3" and "=" the value of txtNumber is still 0.

Recommended Answers

All 2 Replies

Better store the input values in separate variables.
Also check for scope of your variables.

Try the following -

Dim x As Integer

x = txtNumber.Text

x = x + 3
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.