2017-05-24 53 views
1

我無法在文本框中添加2個整數。如果我添加1 + 1,我得到11在2個文本框中添加2個數字

請幫助..

這裏是我的代碼:

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 
+0

'cint'嘗試,而不是VAL,你是串聯 –

+0

這樣的事情? a = CInt(TextBox1.Text) b = CInt(TextBox2.Text) c = CInt(TextBox3.Text) –

+0

謝謝Nathan..It現在可以工作了.. –

回答

1

你需要將值轉換爲cint,正如Nathan_Sav所說,您目前正在串聯字符串。

你需要做這樣的事情:

Private Sub cmdAdd_Click() 

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

End Sub 
+1

嗨,十六,非常感謝你。 Nathan說我加了一個我用在我的頭文件中的那個。 –