【问题标题】:Multiple MsgBoxes多个消息框
【发布时间】: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 块内。不要写这样的代码。

标签: vb.net msgbox


【解决方案1】:
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 Val(TBValue1.Text) <> "" AND IsNumeric(Val(TBValue1.Text)) AND Val(TBValue1.Text) > 0 Then
  If Val(TBValue2.Text) <> "" AND IsNumeric(Val(TBValue2.Text)) AND Val(TBValue2.Text) > 0 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
End Sub 

【讨论】:

    猜你喜欢
    • 2011-08-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-08
    • 2014-05-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多