 |
|
 |
12String Level: Protégé

 Registered: 28-10-2005 Posts: 4
|
Calculator in VB.NET
I lost my post so I am trying again.
I have a basic calculator program that has a few minor bugs or 'System.OverflowException' exceptions.
Here is the code I have so far:
'Declare FirstNum and SecondNum variables
Dim FirstNum, SecondNum As Short
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
End
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'Assign text box values to variables
FirstNum = TextBox1.Text
SecondNum = TextBox2.Text
'Determine checked button and calculate
If RadioButton1.Checked = True Then
TextBox3.Text = FirstNum + SecondNum
End If
If RadioButton2.Checked = True Then
TextBox3.Text = FirstNum - SecondNum
End If
If RadioButton3.Checked = True Then
TextBox3.Text = FirstNum * SecondNum
End If
If RadioButton4.Checked = True Then
TextBox3.Text = FirstNum / SecondNum
End If
End Sub
End Class
Here are my exceptions:
1. When I test to add (+) the following equation, 99999 + 99999 I get a 'System.OverflowException' I need to modify the code to catch and handle this exception so the user can continue.
2. Under the divide (/) function, division by 0 of course will produce an infinite number. Here I want to modify the program so that the user input is validated before the divide operation is performed, and modify the program to raise an exception, then add the code to handle this exception.
3. Under the multiply (*) function, for some reason my program will not take (99 * 999) I need to fix this exception as well.
4. Finally, the subtract (-) wow now here is a good one. If I subtract 32000 - (-767) the answer is 32767, however add one more to the negative (-768) and Bam! another exception.
I want to use Try Catch in all the areas. Can someone help me please.
12String
|
|
04-11-2005 at 09:57 AM |
|
|
|
|
 |
 |