About the Try... Catch I need a little push

vargf

Member
Joined
Feb 15, 2006
Messages
13
Programming Experience
Beginner
Since I got many ideas from all of you I make the code:
________________________________________________________________
Dim FirstNum,Second As Short
________________________________________________________________
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Try

FirstNum = TextBox1.Text
SecondNum = TextBox2.Text
If RadioButton1.Checked = True Then------>This work fine
TextBox3.Text = FirstNum + SecondNum
End If
If RadioButton2.Checked = True Then------>This work fine
TextBox3.Text = FirstNum - SecondNum
End If
If RadioButton3.Checked = True Then----->This Work Fine
TextBox3.Text = FirstNum * SecondNum
End If
If RadioButton4.Checked = True Then----->But in here I have problems
TextBox3.Text = FirstNum / SecondNum
End If
Catch ex As OverflowException
MsgBox("Get real number out of range!", , "Entry error!")
Calculater()
Exit Sub
Catch When Not IsNumeric(TextBox1.Text)
Catch When Not IsNumeric(TextBox2.Text)
MsgBox("Enter a numeric value!", , "Entry error")
Calculater()
Exit Sub
End Try
End Sub
________________________________________________________________
Sub Calculater()
TextBox1.Focus()
TextBox1.SelectionStart = 0
TextBox2.SelectionStart = 0
TextBox1.SelectionLength = Len(TextBox1.Text)
TextBox2.SelectionLength = Len(TextBox2.Text)
End Sub
________________________________________________________________

I did not fine the answer to the zero devision I need to work just this
part Addition,Substraction,multiplication works perfect
I mean When I add 99999 + 99999 Shows me the warnig I put instead
of the overflown messages and the programm do not stop the same with the Subtraction,multiplication I found the answer, but on division is so hard
to get the same as all multiplication,Addition and Subtranction
Please can any body help me Just division all my code I did I need help on the Division thanks all. :confused:
vargf
 
that is DivideByZeroException
 
VB.NET:
If RadioButton4.Checked = True Then
  If SecondNum <> 0 Then TextBox3.Text = FirstNum / SecondNum
End If

Is a start....
 
Back
Top