Jump to content

please help with input data and numeric up/down!

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
3 replies to this topic

#1
tynkir

tynkir

    Newbie

  • Members
  • Pip
  • 3 posts
Hello,
I am new to this forum, I need some help with some c# coding... and please go easy on the jargon I am a first year computing student with very minimal prior knowledge--

I am making a program and I need one of my textbox Input data to be stored (probably would be best put into an array but I could use help with the exact coding for it, it will be a numeric value if this effects the coding for the array)then when I click a button, the Button will reset the input data field so more data can be put in that field and stored again, but NOT overwrite the prior data... (I know how to clear the field with textBox1.Clear () but I need to store the data first)... at the moment I have the data stored when the text is changed with:
private void textBox1_TextChanged(object sender, System.EventArgs e)
{
length1 = Convert.ToInt32(textBox1.Text);
}
but this wont work if I want to store the data multiple times and the field reset when I click a button.

ALSO I have a numeric up/down box and when this field is set I need it to determine how many times the Button can be clicked to reset the Input field.

These are the 2 things I am having difficulty with/dont know the coding for, the rest of it works perfectly... please let me know if I need to give you more information or if you need to see what I have done so far (the actual coding) to help.

Thank you!

#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
If you're storing it in an array, pressing the button should increment an index variable so the next input will go in the next space in the array.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#3
tynkir

tynkir

    Newbie

  • Members
  • Pip
  • 3 posts
ok so I am trying this 2 ways,
first way: I made a loop which breaks after each loop to give the user time to input new data while clearing the field, the problem now seems to be that it isnt adding up all the data, its only storing one set? if you look at the button1_click, this is where my calculations are done, and if you look at the button3_click this is where I THOUGHT my data would store itself, here is my coding (i got rid of any irrelevant code so this isnt the full code):

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace WindowsApplication2
{
	/// <summary>
	/// Summary description for Form1.
	/// </summary>
	public class Form1 : System.Windows.Forms.Form
	{
		private int length1=0, height=0, length2=0, length3=0, length4=0, height2=0, length5=0, length6=0, height3=0, area=0, rolls=0, price=0, cost=0;

		[STAThread]
		static void Main() 
		{
			Application.Run(new Form1());
		}

		private void button1_Click(object sender, System.EventArgs e)
		{
			area = (((length1*2)+(length2*2))*height) + (((length3*2)+(length4*2))*height2) + (((length1*5)+(length6*2))*height3);
			rolls = area/5;
			cost = price*rolls;
			label10.Text =Convert.ToString (area);
			label5.Text =Convert.ToString (rolls);
			label6.Text =Convert.ToString (cost);
		}

		private void comboBox1_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			if (comboBox1.SelectedItem == "Economy")
			{
				price = 8;
			}
			if (comboBox1.SelectedItem == "Luxury")
			{
				price = 15;
			}
		}

		private void button2_Click(object sender, System.EventArgs e)
		{
			ActiveForm.Hide ();
			Form3 f = new Form3();
			f.Show();
		}

		private void button3_Click(object sender, System.EventArgs e)
		{
			for (int i=0; i<3; i++)
			{
				if (i==0)
				{
					length1 = Convert.ToInt32(textBox1.Text);
					length2 = Convert.ToInt32(textBox3.Text);
					height = Convert.ToInt32(textBox2.Text);
					textBox1.Text=null;
					textBox2.Text=null;
					textBox3.Text=null;
					break;
				}
				if (i==1)
				{
					length3 = Convert.ToInt32(textBox1.Text);
					length4 = Convert.ToInt32(textBox3.Text);
					height2 = Convert.ToInt32(textBox2.Text);
					textBox1.Text=null;
					textBox2.Text=null;
					textBox3.Text=null;
					break;
				}
				if (i==2)
				{
					length5 = Convert.ToInt32(textBox1.Text);
					length6 = Convert.ToInt32(textBox3.Text);
					height3 = Convert.ToInt32(textBox2.Text);
					textBox1.Text=null;
					textBox2.Text=null;
			textBox3.Text=null;
		}
	}
	}
}
}
the second way I tried with an array but I am getting errors for this part of the coding:
		private void button3_Click(object sender, System.EventArgs e)
		{
			i++;
			length[i] = Convert.ToInt32(textBox1.Text);
			length1[i] = Convert.ToInt32(textBox3.Text);
			height[i] = Convert.ToInt32(textBox2.Text);
			textBox1.Text=null;
			textBox2.Text=null;
			textBox3.Text=null;
		}
if you know what I am doing wrong for either of these ways it would be a great help, I cant seem to make it work either way.

Edited by WingedPanther, 25 March 2009 - 07:44 AM.
add code tags (the # button)


#4
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
Just looking at the second way (I'm not a C# programmer), are you verifying the text boxes contain ints first? Don't you want to set the text to "" instead of null?
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog