在VB.net中使用多个Texas Box进行计算 [英] Calculations Using multiple Texas Boxes in VB.net
本文介绍了在VB.net中使用多个Texas Box进行计算的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用texbox21.text - texbox60.text = output
到Label1
进行基础减法.数学和函数有效.
这适用于具有相同等式但具有不同texbox的多行,
简单的数学.但是,如果值是空白,则会出现异常错误.这是我的代码,请让我了解我所缺少的内容.
I am trying to do baic subtraction using texbox21.text - texbox60.text = output
to Label1
. The math and function works.
This is for multiple rows of the same kind of equation but with different texboxes,
Simple math. But if the values are blank I get an exception Error. Here is my code please enlighten me on what I am missing.
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
Dim Net1 As Double
Dim Net2 As Double
Dim Loaded1 As Double
Dim End1 As Double
Loaded1 = Double.Parse(TextBox21.Text)
End1 = Double.Parse(TextBox60.Text)
Dim Loaded2 As Double
Dim End2 As Double
If TextBox21.Text And TextBox60.Text = False Then
Net1 = False
End If
If TextBox21.Text And TextBox60.Text = True Then
Loaded1 = Double.Parse(TextBox21.Text)
End1 = Double.Parse(TextBox60.Text)
Net1 = Loaded1 - End1
Label2.Text = Net1.ToString
End If
End Sub
推荐答案
类似的方法应该起作用:
Something like this should work:
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
If TextBox1.Text = "" Or TextBox2.Text = "" Then
Exit Sub
End If
Dim Net1 As Double
Dim Net2 As Double
If Double.TryParse(TextBox1.Text, Net1) And Double.TryParse(TextBox2.Text, Net2) Then
Label2.Text = Net1 - Net2
Else
If Not Double.TryParse(TextBox1.Text, Net1) Then
MessageBox.Show("Value in first textbox cannot be converted to a Double")
Exit Sub
Else
MessageBox.Show("Value in second textbox cannot be converted to a Double")
Exit Sub
End If
End If
End Sub
这篇关于在VB.net中使用多个Texas Box进行计算的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文