【问题标题】:Adding 2 Numbers in 2 TextBox在 2 个文本框中添加 2 个数字
【发布时间】:2017-05-24 23:16:52
【问题描述】:

我在 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 尝试而不是 val,您正在连接
  • 这样的? a = CInt(TextBox1.Text) b = CInt(TextBox2.Text) c = CInt(TextBox3.Text)
  • 谢谢你,Nathan..它现在可以工作了..

标签: vba add


【解决方案1】:

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

你需要做这样的事情:

Private Sub cmdAdd_Click()

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

End Sub

【讨论】:

  • 嗨,Hexie,非常感谢你。它就像 Nathan 所说的那样工作,我也添加了我在标题帖子中使用的那个......请参阅..
猜你喜欢
  • 2014-04-03
  • 1970-01-01
  • 1970-01-01
  • 2016-01-20
  • 2013-08-27
  • 2022-07-07
  • 2016-06-12
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多