在 2 个文本框中添加 2 个数字

Adding 2 Numbers in 2 TextBox

我在 TextBox 中添加 2 个整数时遇到问题。如果我加 1 + 1 我得到 11.

请帮忙..

这是我的代码:

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

我使用了这段代码,它也有效:

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

        txtTotal.Value = x

您需要将值转换为 cint,正如 Nathan_Sav 所说,您当前正在连接字符串。

你需要做这样的事情:

Private Sub cmdAdd_Click()

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

End Sub