将未启用的文本框与启用为零

时间:2016-05-12 13:20:31

标签: vb.net

我在一个表单中使用9个文本框,我希望应用程序将数字加到另一个表单中的另一个标签中,用户不必填写所有9个文本框,所以我使用了9个复选框来启用每个文本框分开。 问题是,当我点击按钮,假设在不检查所有9个复选框的情况下进行求和方程式并填充9个文本框,应用程序停止并显示错误。 我想总结一个textbox.enabled = false 为零 那是我的按钮代码:

Private Sub Button1_Click(Sender As Object, e As EventArgs) Handles Button1.Click
   Me.Hide()
   Form5.Show()
   Dim intNum1 As Decimal
   Dim intNum2 As Decimal
   Dim intNum3 As Decimal
   Dim intNum4 As Decimal
   Dim intNum5 As Decimal
   Dim intNum6 As Decimal
   Dim intNum7 As Decimal
   Dim intNum8 As Decimal
   Dim intNum9 As Decimal
   intNum1 = Decimal.Parse(TextBox1.Text)
   intNum2 = Decimal.Parse(TextBox2.Text)
   intNum3 = Decimal.Parse(TextBox3.Text)
   intNum4 = Decimal.Parse(TextBox4.Text)
   intNum5 = Decimal.Parse(TextBox5.Text)
   intNum6 = Decimal.Parse(TextBox6.Text)
   intNum7 = Decimal.Parse(TextBox7.Text)
   intNum8 = Decimal.Parse(TextBox8.Text)
   intNum9 = Decimal.Parse(TextBox9.Text)
   Form5.Label1.Text = intNum1 + intNum2 + intNum3 + intNum4 + intNum5 + intNum6 + intNum7 + intNum8 + intNum9

1 个答案:

答案 0 :(得分:0)

你应该使用

intNum1 = Val(TextBox1.Text)

而不是

intNum1 = Decimal.Parse(TextBox1.Text)