【问题标题】:Text box does not recognize integer文本框无法识别整数
【发布时间】:2014-10-10 05:21:55
【问题描述】:

我在 Visual Basic Express Edition 2010 上构建计算器。

但是当我运行代码时,这行会出错

TextBox3 = c

错误 1“整数”类型的值无法转换为“System.Windows.Forms.TextBox”。 C:\Users\INFRA\AppData\Local\Temporary Projects\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

结束类

【问题讨论】:

  • c.ToString(),您不能在文本中输入整数。而且,它的textbox .Text

标签: vb.net visual-studio-2010 vb.net-2010


【解决方案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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-03-10
    • 1970-01-01
    • 2018-08-08
    • 2017-04-12
    • 1970-01-01
    • 2021-02-12
    • 1970-01-01
    相关资源
    最近更新 更多