A
Andrea
....without changing the data type. I have been working on this for over 5 hours, please help me so I don't have to shoot myself. It's due by midnight...
Here's my code:
(Variables are declared as Short, therefore any sum over 32767 causes an overflow exception.)
If RadioButton1.Checked = True Then
Try
TextBox3.Text = FirstNum + SecondNum
Catch ex As OverflowException
MsgBox("Sum of Variable 1 and Variable 2 is greater than maximum allowed.", MsgBoxStyle.OKOnly, "Maximum Value Exceeded")
TextBox1.Clear()
TextBox2.Clear()
TextBox3.Clear()
TextBox1.Focus()
Return
End Try
End If
If RadioButton2.Checked = True Then
'Test for Overflow exception
Try
TextBox3.Text = FirstNum - SecondNum
Catch MyErr As ArithmeticException
MsgBox("Sum of Variable 1 and Variable 2 is greater than maximum allowed.", MsgBoxStyle.OKOnly, "Maximum Value Exceeded")
TextBox1.Clear()
TextBox2.Clear()
TextBox3.Clear()
TextBox1.Focus()
Return
End Try
End If
The problem is, it works for values a little bit over the range, but not if you put in 99999 plus 99999. I can't figure out why and how it is differentiating, if it isn't simply the limit of the Short data type.
Anyone that can help, I will buy you a drink!!!
Here's my code:
(Variables are declared as Short, therefore any sum over 32767 causes an overflow exception.)
If RadioButton1.Checked = True Then
Try
TextBox3.Text = FirstNum + SecondNum
Catch ex As OverflowException
MsgBox("Sum of Variable 1 and Variable 2 is greater than maximum allowed.", MsgBoxStyle.OKOnly, "Maximum Value Exceeded")
TextBox1.Clear()
TextBox2.Clear()
TextBox3.Clear()
TextBox1.Focus()
Return
End Try
End If
If RadioButton2.Checked = True Then
'Test for Overflow exception
Try
TextBox3.Text = FirstNum - SecondNum
Catch MyErr As ArithmeticException
MsgBox("Sum of Variable 1 and Variable 2 is greater than maximum allowed.", MsgBoxStyle.OKOnly, "Maximum Value Exceeded")
TextBox1.Clear()
TextBox2.Clear()
TextBox3.Clear()
TextBox1.Focus()
Return
End Try
End If
The problem is, it works for values a little bit over the range, but not if you put in 99999 plus 99999. I can't figure out why and how it is differentiating, if it isn't simply the limit of the Short data type.
Anyone that can help, I will buy you a drink!!!