2 Replies - 3144 Views - Last Post: 22 September 2009 - 12:23 AM Rate Topic: -----

#1 megglz  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 11
  • View blog
  • Posts: 414
  • Joined: 22-August 08

Basic Calculator textbox

Post icon  Posted 15 September 2009 - 06:20 AM

Currently giving the tutorial on Basic Calculator a go.

Having a minor issue at the moment, can't figure out what's wrong even though it's right in front of me! When I click the button on my calculator it doesnt enter it into my textbox.

I've the textbox set to readonly and TabStop is also set to false.

Anyone know what I'm doing wrong?

Code so far..

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 BasicCalculator
{
	public partial class Form1 : Form
	{
		public Form1()
		{
			InitializeComponent();
		}

		// variables to hold operands
		private double valueHolder1;
		private double valueHolder2;

		// variable to hold temporary values
		private double tempValue;

		// True if '.' is use else false
		private bool hasDecimal = false;
		private bool inputStatus = true;

		// variable to hold Operator
		private string calcFunc;

		//Button for integer 0
		private void button1_Click(object sender, EventArgs e)
		{
			//Check the input Status
			if (inputStatus)
			{
				//If True
				//Check to make sure the
				//inputbox has a value
				if (txtInput.Text.Length >= 1)
				{
					//Add zero
					txtInput.Text += button1.Text;
				}
			}

		}
	}

}


This post has been edited by irishgirl: 15 September 2009 - 06:21 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Basic Calculator textbox

#2 janne_panne  Icon User is offline

  • WinRT Dev
  • member icon

Reputation: 428
  • View blog
  • Posts: 1,047
  • Joined: 09-June 09

Re: Basic Calculator textbox

Posted 15 September 2009 - 06:30 AM

The zero doesn't go into the textbox because of this:
if (txtInput.Text.Length >= 1)



txtInput is probably empty so that condition is false.

That is to prevent a number like "00012" in the textbox because the zeros are pointless.

Continue the tutorial and add another buttons for numbers 1-9 and then try to input number like "10" and that button above will also work.
Was This Post Helpful? 1
  • +
  • -

#3 carle  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 25
  • Joined: 21-September 09

Re: Basic Calculator textbox

Posted 22 September 2009 - 12:23 AM

Hi,

Because of (txtInput.Text.Length >= 1).

if your txtInput is empty ,you can not input zero into it.


Carle
_____________________
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1