2014-10-10 25 views
0

我上的Visual Basic速成版構建計算器2010文本框不承認整數

,但是當我運行代碼時出錯此行

TextBox3 = c 

錯誤1個值類型的「整數」不能被轉換爲'System.Windows.Forms.TextBox'。 C:\用戶\基建\應用程序數據\本地\臨時項目\ WindowsApplication1 \ Form1.vb的7月20 WindowsApplication1

完整代碼是:

Public Class Form1 
Dim a, b, c As Integer 
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 
    a = Val(TextBox1) 
    b = Val(TextBox2) 
    c = a + b 
    TextBox3 = c 

End Sub 

末級

+1

'c.ToString()',你不能在文本中輸入整數。還有,它的'textbox .Text' – kks21199 2014-10-10 09:49:20

回答

1

您需要使用Text屬性的文本框。

Public Class Form1 
Dim a, b, c As Integer 
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 
    a = Val(TextBox1.Text) 
    b = Val(TextBox2.Text) 
    c = a + b 
    TextBox3.Text = c.ToString() 

End Sub