Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vba 在2文本框中添加2个数字_Vba_Add - Fatal编程技术网

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

Vba 在2文本框中添加2个数字,vba,add,Vba,Add,在文本框中添加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 =

在文本框中添加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

cint
try而不是val,你是在连接这样的东西吗?a=CInt(TextBox1.Text)b=CInt(TextBox2.Text)c=CInt(TextBox3.Text)谢谢你Nathan.它现在可以用了Hexie,非常感谢你.它和Nathan说的一样有效.我还添加了我在头条文章中使用的那一个.请看。。