7 Replies - 2394 Views - Last Post: 16 June 2009 - 09:58 AM Rate Topic: -----

#1 jordie91  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 46
  • Joined: 13-June 09

catch infinity on my calculator

Posted 16 June 2009 - 04:15 AM

i know i can catch errors on a calculator with try and catch

but i dont know wher and how i can combine with this code

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication4
{
	public partial class Form1 : Form
	{
		public Form1()
		{
			InitializeComponent();
		}

		private void Form1_Load(object sender, EventArgs e)
		{
			

 

		}

		private void button1_Click(object sender, EventArgs e)//hier wordt plus aangemaakt
		{
			float A, B, C;

			A = Convert.ToInt32(textBox1.Text);
			B = Convert.ToInt32(textBox2.Text);
			C = A + B;

			textBox3.Text = C.ToString();
		}

		private void button2_Click(object sender, EventArgs e)/// hier wordt min aangemaakt
		{
			float A, B, C;

			A = Convert.ToInt32(textBox1.Text);
			B = Convert.ToInt32(textBox2.Text);
			C = A - B;

			textBox3.Text = C.ToString();
		}

		private void button3_Click(object sender, EventArgs e)// hier wordt keer aangemaakt
		{
			float A, B, C;

			A = Convert.ToInt32(textBox1.Text);
			B = Convert.ToInt32(textBox2.Text);
			C = A * B;

			textBox3.Text = C.ToString();
		}

		private void button4_Click(object sender, EventArgs e)// hier wordt gedeeld door aangemaakt
		{
			float A, B, C;

			A = Convert.ToInt32(textBox1.Text);
			B = Convert.ToInt32(textBox2.Text);
			C = A /  B;

			textBox3.Text = C.ToString();
		}

		private void button5_Click(object sender, EventArgs e) // hier wordt machten mee aangemaakt
		{
			double A,C;

			A = Convert.ToInt32(textBox1.Text);
			C = Math.Sqrt(A);

			textBox3.Text = C.ToString();
		}

		private void label3_Click(object sender, EventArgs e)
		{
		  
		}

		private void textBox3_TextChanged(object sender, EventArgs e)
		{

		}

		private void button6_Click(object sender, EventArgs e)//macht
		{
			double A,B, C;

			A = Convert.ToInt32(textBox1.Text);
			B = Convert.ToInt32(textBox2.Text);
			C = Math.Pow(A,B);

			textBox3.Text = C.ToString();
		}
	}
}



and i also dont know how to use try and catch

Is This A Good Question/Topic? 0
  • +

Replies To: catch infinity on my calculator

#2 RudiVisser  Icon User is offline

  • .. does not guess solutions
  • member icon

Reputation: 1003
  • View blog
  • Posts: 3,562
  • Joined: 05-June 09

Re: catch infinity on my calculator

Posted 16 June 2009 - 04:18 AM

http://msdn.microsof...esw(VS.71).aspx

Wrap try/catch round every button click. You could also assign an unhandled exception handler which will handle everything that you don't.
Was This Post Helpful? 0
  • +
  • -

#3 noorahmad  Icon User is offline

  • Untitled
  • member icon

Reputation: 209
  • View blog
  • Posts: 2,290
  • Joined: 12-March 09

Re: catch infinity on my calculator

Posted 16 June 2009 - 04:24 AM

use try catch like this:
try
			{
				//your code here	
			}
			catch (Exception ex)
			{
				MessageBox.Show(ex.Message);
			}

Was This Post Helpful? 0
  • +
  • -

#4 jordie91  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 46
  • Joined: 13-June 09

Re: catch infinity on my calculator

Posted 16 June 2009 - 04:39 AM

and how do i add a message like "je getal is oneindig " if the number is infinity ?
Was This Post Helpful? 0
  • +
  • -

#5 noorahmad  Icon User is offline

  • Untitled
  • member icon

Reputation: 209
  • View blog
  • Posts: 2,290
  • Joined: 12-March 09

Re: catch infinity on my calculator

Posted 16 June 2009 - 04:39 AM

and also change float to decimal
 try
			{
				if ((textBox1.Text == string.Empty) && (textBox2.Text == string.Empty))
				{
					return;
				}
				decimal A, B, C;
				A = Convert.ToDecimal(textBox1.Text);
				B = Convert.ToDecimal(textBox2.Text);

				C = A * B;
				textBox3.Text = C.ToString();

			}
			catch (Exception ex)
			{
				MessageBox.Show(ex.Message);
			}

Was This Post Helpful? 0
  • +
  • -

#6 jordie91  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 46
  • Joined: 13-June 09

Re: catch infinity on my calculator

Posted 16 June 2009 - 04:54 AM

now i only have a error if there is nothing in a texbox but i want a message to catch by c=infinity
see code

This post has been edited by jordie91: 16 June 2009 - 04:56 AM

Was This Post Helpful? 0
  • +
  • -

#7 eclipsed4utoo  Icon User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1524
  • View blog
  • Posts: 5,960
  • Joined: 21-March 08

Re: catch infinity on my calculator

Posted 16 June 2009 - 06:40 AM

View Postjordie91, on 16 Jun, 2009 - 06:54 AM, said:

now i only have a error if there is nothing in a texbox but i want a message to catch by c=infinity
see code


what do you mean, "catch infinity"? there is no infinity in C#. How are you getting infinity?
Was This Post Helpful? 0
  • +
  • -

#8 born2c0de  Icon User is offline

  • printf("I'm a %XR",195936478);
  • member icon

Reputation: 180
  • View blog
  • Posts: 4,667
  • Joined: 26-November 04

Re: catch infinity on my calculator

Posted 16 June 2009 - 09:58 AM

Quote

what do you mean, "catch infinity"? there is no infinity in C#. How are you getting infinity?

jordie91 is actually referring to the "Divide By Zero" or "Overflow" error.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1