-2

I keep receiving multiple MsgBoxes with the same error messages. How do I keep this from happening?

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
HaveNoDisplayName
  • 8,291
  • 106
  • 37
  • 47
Michiel13
  • 1
  • 1

1 Answers1

0
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 
Zeddy
  • 2,079
  • 1
  • 15
  • 23