vb.net 上的简单计算
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17918007/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Simple calculations on vb.net
提问by Greenhorn
I am using VB.NET, i am new to VB.NET and i tried to make simple form with calculations such as addition, subtraction and multiplications and divisions by using text boxes and buttons. For my project i need to calculate three vales by using three formulas. The three vales then need to be multiplied in order to get the final value.
我正在使用 VB.NET,我是 VB.NET 的新手,我试图通过使用文本框和按钮来制作简单的表格,如加法、减法、乘法和除法。对于我的项目,我需要使用三个公式计算三个值。然后需要将三个值相乘以获得最终值。
Here are the formulas used:
以下是使用的公式:
Availability = (Operating time - downtime)/Operating time x 100
可用性 =(运行时间 - 停机时间)/运行时间 x 100
Performance efficiency = (Theoretical Cycle time x Processed amount)/ Operating time x 100
性能效率 =(理论循环时间 x 处理量)/ 操作时间 x 100
Rate of Quality = (Processed amount - defect amount)/ processed amount x 100
合格率=(加工量-缺陷量)/加工量×100
Overall Equipment Effectiveness = Availability x Performance efficiency x Rate of Quality
整体设备效率 = 可用性 x 性能效率 x 质量率
I managed to get the values for the 3 formulas, however whenever i tried to get the final value (Overall Equipment Effectiveness = Availability x Performance efficiency x Rate of Quality) the value i get is still 0, and all the other values i calculated turn to 0 as well. I will post my code below, any help is much appreciated. Thank you for your time and patience :)
我设法获得了 3 个公式的值,但是每当我试图获得最终值(整体设备效率 = 可用性 x 性能效率 x 质量率)时,我获得的值仍然为 0,而我计算的所有其他值都会转也为 0。我将在下面发布我的代码,非常感谢任何帮助。感谢您的时间和耐心:)
Public Class OEE
Private Sub OEE_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub Label9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
End Sub
Private Sub TextBox9_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim number1 As Integer
Dim number2 As Integer
Dim answer1 As Decimal
Dim sum1 As Integer
Dim sum2 As Integer
number1 = TextBox5.Text
number2 = TextBox6.Text
sum1 = number1 - number2
sum2 = number1 * 100
answer1 = sum1 / sum2
TextBox4.Text = answer1
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim number3 As Integer
Dim number4 As Integer
Dim number5 As Integer
Dim answer2 As Decimal
Dim sum3 As Integer
Dim sum4 As Integer
number3 = TextBox2.Text
number4 = TextBox11.Text
number5 = TextBox5.Text
sum3 = number3 * number5
sum4 = number4 * 100
answer2 = sum3 / sum4
TextBox1.Text = answer2
End Sub
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim number6 As Integer
Dim number7 As Integer
Dim answer3 As Decimal
Dim sum5 As Integer
Dim sum6 As Integer
number6 = TextBox11.Text
number7 = TextBox8.Text
sum5 = number6 - number7
sum6 = number6 * 100
answer3 = sum5 / sum6
TextBox7.Text = answer3
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
Dim answer1 As Decimal
Dim answer2 As Decimal
Dim answer3 As Decimal
Dim total As Decimal
TextBox4.Text = answer1
TextBox1.Text = answer2
TextBox7.Text = answer3
total = answer1 * answer2 * answer3
TextBox10.Text = total
End Sub
Private Sub TextBox10_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox10.TextChanged
End Sub
End Class
回答by Louis van Tonder
To start with:
首先:
In your last code routine, your are equaling the textboxes to the decimals, you should equal the decimals to the textboxes?
在您的最后一个代码例程中,您将文本框等于小数,您应该将小数等于文本框吗?
answer1 = TextBox4.Text
answer2 = TextBox1.Text
answer3 = TextBox7.Text
total = answer1 * answer2 * answer3

