Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim day1 As Double
Dim lea As Double
day1 = Val(TextBox1.Text / 30)
lea = (CDbl(TextBox2.Text * day1))
TextBox3.Text = lea
Dim pf As Double
Dim esi As Double
Dim loan As Double
Dim net As Double
'Dim leave As Double
'leave = (CDbl(TextBox1.Text) * 2.0) / 100
pf = (CDbl(TextBox1.Text) * 4.0) / 100
esi = (CDbl(TextBox1.Text) * 3.0) / 100
'TextBox2.Visible = True
'TextBox3.Visible = True
'TextBox4.Visible = True
'TextBox5.Visible = True
'TextBox6.Visible = True
TextBox4.Text = CStr(pf)
TextBox5.Text = CStr(esi)
TextBox6.Text=0
If TextBox1.Text > 0 Then
loan = (CDbl(TextBox1.Text) * 2.0) / 100
TextBox6.Text = CStr(loan)
End If
net = (CDbl(TextBox1.Text) - (TextBox3.Text + pf + esi + loan))
'TextBox6.Text = CStr(net)
End Sub
3 回答
你的括号放错地方了。
利用:
day1 = Val(TextBox1.Text) / 30
lea = CDbl(TextBox2.Text) * day1
我不能给你一个完整的答案,因为你的代码中使用的变量对理解你想要做什么没有多大帮助,但作为一个建议,我将尝试解释如何使用double.TryParse。
此方法尝试将来自用户 (textbox.text) 的输入转换为双精度。如果转换成功,则使用转换结果初始化传递的双精度变量,并且方法返回 true。如果转换失败,该方法返回 false。
.....
if Not double.TryParse(TextBox1.Text, day1) Then
MessageBox.Show("Not a valid number typed")
return
End If
' Now with this line you don't get failed conversion from strings'
day1 = day1 / 30
Dim temp As Double
if Not double.TryParse(TextBox2.Text, temp) Then
MessageBox.Show("Not a valid number typed")
return
End If
' again no conversion problems here '
lea = temp * day1
.... the rest of your code should reuse the conversion already made for
.... textbox1.Text and textBox2.Text ....
最后一个提示:您谈论的是工资系统,因此您正在处理货币价值。在这种情况下,最好使用十进制变量而不是双精度数。小数更好地处理货币值,并且不会遭受作为浮点变量的舍入问题。
此外,十进制类型具有来自其类方法的 TryParse 方法。
将第 1 天昏暗为双倍
Dim lea As Double
day1 = Val(TextBox1.Text / 30)
lea = (CDbl(TextBox2.Text)) * (day1)
TextBox3.Text = CStr(lea)
将 pf 调暗为 Double
Dim esi As Double
Dim Loan As Double
暗网为双
pf = (CDbl(TextBox1.Text) * 4.0) / 100
esi = (CDbl(TextBox1.Text) * 3.0) / 100
TextBox4.Text = CStr(pf)
TextBox5.Text = CStr(esi)
贷款 = (CDbl(TextBox6.Text) * 2.0) / 100
net = (CDbl(TextBox1.Text)) - (TextBox3.Text + pf + esi + loan)
TextBox7.Text = CStr(net)