Bamboo LikeFox
Bamboo LikeFox

Reputation: 35

Adding 2 Numbers in 2 TextBox

I'm having trouble adding 2 Integers in TextBox. If I add 1 + 1 I get 11.

Please help..

Here's my code:

Private Sub cmdAdd_Click()

Dim a As Integer
Dim b As Integer
Dim c As Integer

a = CInt(TextBox1.Text)
b = CInt(TextBox2.Text)
c = CInt(TextBox3.Text)

TextBox3.Value = TextBox1.Value + TextBox2.Value

c = a + b

End Sub

I used this code and it works too:

 x = CDbl(txtSurveyYes.Value) + CDbl(txtSurveyNo.Value)

        txtTotal.Value = x

Upvotes: 1

Views: 1280

Answers (1)

Hexie
Hexie

Reputation: 4213

You need to cast the value to cint, as Nathan_Sav said, you are currently concatenating strings.

You would need to do something like this:

Private Sub cmdAdd_Click()

TextBox3.Value = CInt(TextBox1.Value) + CInt(TextBox2.Value)

End Sub

Upvotes: 1

Related Questions