Cannot make calculations with textbox

I am using a form to make calculations and I cannot enter a second val

Page 1 of 1

6 Replies - 767 Views - Last Post: 06 June 2009 - 11:09 PM Rate Topic: -----

#1 Wingzerorx93  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 28
  • Joined: 18-April 09

Cannot make calculations with textbox

Post icon  Posted 06 June 2009 - 08:48 PM

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 WindowsFormsApplication1
{
	public partial class Calclulator : Form
	{
		private double num1 = 0, num2 = 0;
		private string oper = "";
		public Calclulator()
		{
			InitializeComponent();
		}
	   private void anyNumber_Click(object sender, EventArgs e)
		{
			Button theButton = (Button)sender;
			this.richTextBox1.Text += theButton.Text;
		}

		private void anyOperator_Click(object sender, EventArgs e)
		{
			num1 = Convert.ToDouble(this.richTextBox1.Text);
			num2 = Convert.ToDouble(this.richTextBox1.Text);
			// Do the operation stored in oper variable

			Button theButton = (Button)sender;
			this.oper = theButton.Text;
		}

		public double calc()
		{
			double answer;
			answer = 0;
			switch (this.oper)
			{
				case "+":
					answer = num1 + num2;
					break;
				case "-":
					answer = num1 - num2;
					break;
				case "*":
					answer = num1 * num2;
					break;
				case "/":
					answer = num1 / num2;
					break;
				case "=":
					answer = num2;
					break;
				default:
					answer = 0;
					break;
			}
			return answer;
		}

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

		private void help_Click(object sender, MouseEventArgs e)
		{
	   
		}

		
	}
}


I am using a form to make calculations and I cannot enter a second value.

Is This A Good Question/Topic? 0
  • +

Replies To: Cannot make calculations with textbox

#2 zombie_chan51  Icon User is offline

  • D.I.C Regular

Reputation: 7
  • View blog
  • Posts: 327
  • Joined: 16-March 08

Re: Cannot make calculations with textbox

Posted 06 June 2009 - 10:35 PM

Why are you using richTextBox and not TextBox
Was This Post Helpful? 0
  • +
  • -

#3 Wingzerorx93  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 28
  • Joined: 18-April 09

Re: Cannot make calculations with textbox

Posted 06 June 2009 - 10:59 PM

View Postdrjoe51, on 6 Jun, 2009 - 09:35 PM, said:

Why are you using richTextBox and not TextBox

Should I use TextBox instead?
Was This Post Helpful? 0
  • +
  • -

#4 noorahmad  Icon User is offline

  • Untitled
  • member icon

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

Re: Cannot make calculations with textbox

Posted 06 June 2009 - 11:04 PM

yes you can use it.
Was This Post Helpful? 0
  • +
  • -

#5 Wingzerorx93  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 28
  • Joined: 18-April 09

Re: Cannot make calculations with textbox

Posted 06 June 2009 - 11:06 PM

View Postnoorahmad, on 6 Jun, 2009 - 10:04 PM, said:

yes you can use it.

Is it correct for me to use richTextBox?
Was This Post Helpful? 0
  • +
  • -

#6 noorahmad  Icon User is offline

  • Untitled
  • member icon

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

Re: Cannot make calculations with textbox

Posted 06 June 2009 - 11:07 PM

check here http://www.dreaminco...h...c=32968&hl=

yes it is but if you use TextBox it will be better.
Was This Post Helpful? 1
  • +
  • -

#7 Wingzerorx93  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 28
  • Joined: 18-April 09

Re: Cannot make calculations with textbox

Posted 06 June 2009 - 11:09 PM

View Postnoorahmad, on 6 Jun, 2009 - 10:07 PM, said:

check here http://www.dreaminco...h...c=32968&hl=

yes it is but if you use TextBox it will be better.

Thanks for the tip, I'll check the link you gave me and change to TextBox.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1