[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Visual Studio.NET 2003 and Basic Math Application.

Posted on 2004-04-17
11
Medium Priority
?
250 Views
Last Modified: 2013-12-29
I am still learning VB.NET This is problably so simple, that I am not sure what I am missing to solve the codes error messages.
If someone is able to assist, it would be greatly appreciated.

I have a basic math calculator program. This application was designed to perform basic math calculations: +, -, *, /. The program was provided for us and we have to fix the errors in it. I have to keep the varaibles declared as short.


1. Test all operators with the values 8 and 2 to make sure it works as expected.
2. Test the program with 99999 + 99999. This should raise a 'System.OverflowException’ exception.
3. Modify the code to catch and handle the exception so that the user can continue. KEEP the declarations of FirstNum and SecondNum as short.
4. Test the program with ‘9 divide 0’. The result shows ‘infinity’. Actually, the calculation should raise an exception ‘System.DivideByZeroException’. Modify the program so that the user input is validated before the divide operation is performed. For a divide by zero, modify the program to raise an exception, then add the code to handle the exception.
5. Try the test (99 * 999). You should get a 'System.OverflowException’ exception. Fix the problem to handle the exception.
6. Now test the '-' operator using the following test cases: (1) variable1 = 32000 and variable2 = -767 and (2) variable1 = 32000 and variable2 = -768. For the first test case, the result should be 32767. For the second test case, you should get an exception. Explain what is different from the first case and fix the problem to handle the exception.
7. Make sure to create a user-friendly interface to guide the user after the exceptions are handled.


I have stated the code below.

'Declare FirstNum and SecondNum variables as global
    Dim FirstNum, SecondNum As Short

 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
        Try
            If RadioButton1.Checked = True Then
                TextBox3.Text = FirstNum + SecondNum
            End If
        Catch Exc As System.OverflowException
            MessageBox.Show("Please choose smaller number")
        End Try
        'Determine checked button and calculate

        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
0
Comment
Question by:jdocchio01
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
  • 2
11 Comments
 
LVL 101

Expert Comment

by:mlmcc
ID: 10853775
This sure looks like a homework assignment.  As such the experts cannot fully answer or write the code for you but we can help with code you have produced and specific questions you may have.

It appears you have an excellent start.  What is your problem?

mlmcc
0
 
LVL 4

Expert Comment

by:venishjoe
ID: 10854187
Hai,

    What you expect us do now? you haven't posted any question?

Anyhow follow the links given below to get a sample code for calculator in VB.NET

http://www.developerfusion.com/show/160/
http://www.planetsourcecode.com/vb/scripts/ShowCode.asp?txtCodeId=748&lngWId=10
http://www.planetsourcecode.com/vb/scripts/ShowCode.asp?txtCodeId=2094&lngWId=10
http://www.programmersheaven.com/c/msgboard/read.asp?Board=39&MsgID=253741&Setting=A9999F0001

Hope these helps

If you have any specific problems in the code you can post it.

Regards
Venish
0
 

Author Comment

by:jdocchio01
ID: 10855452
Hi folks,

All I would like to know is can this be completed using Try/Catch statements in the code itself to intercept error messages?

Thank you for your time.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 101

Expert Comment

by:mlmcc
ID: 10855716
Yes it can.  Just like you did in the sample.

mlmcc
0
 

Author Comment

by:jdocchio01
ID: 10855751
Ok I will go fiddle around with the remainder of the program.  
If I have any issues may I still ask questions?
0
 

Author Comment

by:jdocchio01
ID: 10855755
Forgot to thank you :)
0
 
LVL 101

Expert Comment

by:mlmcc
ID: 10856203
Sure you can.  Just make them specific and provide the details.

mlmcc
0
 

Author Comment

by:jdocchio01
ID: 10856793
Hi,

I have figured out 1, 2, 3, and 5. and I think I can handle number 6. I have most of my errors evaluated and repaired.

Although number 4 I not sure of.  What would be the best way to handle this situation?
Should I place a statement to warn the user of this error first before the
TextBox3.Text = FirstNum / SecondNum, or before the If statement?



0
 
LVL 4

Accepted Solution

by:
venishjoe earned 2000 total points
ID: 10857075
Hai,

Well, you can place the statement after the If Statement and before the TextBox3.Text = FirstNum / SecondNum.
hope you got your answer.

Regards
Venish
0
 

Author Comment

by:jdocchio01
ID: 10860954
I have the program fully running to its specifications.  I Thank you both soooooooo much for your help.
0

Featured Post

Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
A short article about problems I had with the new location API and permissions in Marshmallow
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question