【发布时间】:2015-05-24 14:02:03
【问题描述】:
我不断收到多个带有相同错误消息的 MsgBox。如何防止这种情况发生?
Private Sub BtnCalc_Click(sender As Object, e As EventArgs) Handles BtnCalc.Click
Dim intValue1 As Integer
Dim intValue2 As Integer
Dim intValue3 As Integer
intValue1 = Val(TBValue1.Text)
intValue2 = Val(TBValue2.Text)
intValue3 = Val(TBValue3.Text)
If IsNumeric(Val(TBValue1.Text)) Then
If IsNumeric(Val(TBValue2.Text)) Then
If Val(TBValue1.Text) > 0 Then
If Val(TBValue2.Text) > 0 Then
If Val(TBValue1.Text) <> "" Then
If Val(TBValue2.Text) <> "" Then
TBValue3.Text = a + ((Val(TBValue1.Text) - >Val(TBValue2.Text)) * 10)
If Val(TBValue1.Text) > Val(TBValue2.Text) + x
Then MsgBox("Error2")
End If
Else : MsgBox("Error!")
TBValue1.Text = ""
TBValue2.Text = ""
TBValue3.Text = ""
End If
Else : MsgBox("Error!")
TBValue1.Text = ""
TBValue2.Text = ""
TBValue3.Text = ""
End If
Else : MsgBox("Error!")
TBValue1.Text = ""
TBValue2.Text = ""
TBValue3.Text = ""
End If
Else : MsgBox("Error!")
TBValue1.Text = ""
TBValue2.Text = ""
TBValue3.Text = ""
End If
MsgBox("Error!")
TBValue1.Text = ""
TBValue2.Text = ""
TBValue3.Text = ""
End If
MsgBox("Error!")
TBValue1.Text = ""
TBValue2.Text = ""
TBValue3.Text = ""
End If
End Sub
End Class
【问题讨论】:
-
它让我的眼睛流血了,但最后两个 MsgBox() 调用属于 Else 块内。不要写这样的代码。