AOA AOA AOA Folding For Team 45 AOA Files Home Front Page Become an AOA Subscriber! UserCP Calendar Memberlist FAQ Search Forum Home


Go Back   AOA > Software > Programming and Assembly Language

Programming and Assembly Language Please read this Topic's rules!!

Reply
 
LinkBack Thread Tools Rate Thread
  #1 (permalink)  
Old 29th January, 2007, 05:47 AM
MrSeanKon's Avatar
OcBible Creator
 
Join Date: June 2005
Location: Where the streets have no name
Posts: 766

Question GKR how can I use for loop to access textboxes in C#??

The source code is:

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

public class Form1 : System.Windows.Forms.Form
{
	private System.Windows.Forms.TextBox textBox1;
	private System.Windows.Forms.TextBox textBox2;
	private System.Windows.Forms.TextBox textBox3;
	private System.Windows.Forms.TextBox textBox4;
	private System.Windows.Forms.Button button1;
	private System.ComponentModel.Container components = null;

	public Form1()
	{
		InitializeComponent();
	}
	protected override void Dispose( bool disposing )
	{
		if( disposing )
		{
			if (components != null) 
			{
				components.Dispose();
			}
		}
		base.Dispose( disposing );
	}

	#region Windows Form Designer generated code
	private void InitializeComponent()
	{
		this.textBox1 = new System.Windows.Forms.TextBox();
		this.textBox2 = new System.Windows.Forms.TextBox();
		this.textBox3 = new System.Windows.Forms.TextBox();
		this.textBox4 = new System.Windows.Forms.TextBox();
		this.button1 = new System.Windows.Forms.Button();
		this.SuspendLayout();
		// 
		// textBox1
		// 
		this.textBox1.Location = new System.Drawing.Point(16, 24);
		this.textBox1.Name = "textBox1";
		this.textBox1.Size = new System.Drawing.Size(48, 20);
		this.textBox1.TabIndex = 0;
		this.textBox1.Text = "";
		// 
		// textBox2
		// 
		this.textBox2.Location = new System.Drawing.Point(16, 56);
		this.textBox2.Name = "textBox2";
		this.textBox2.Size = new System.Drawing.Size(48, 20);
		this.textBox2.TabIndex = 1;
		this.textBox2.Text = "";
		// 
		// textBox3
		// 
		this.textBox3.Location = new System.Drawing.Point(16, 88);
		this.textBox3.Name = "textBox3";
		this.textBox3.Size = new System.Drawing.Size(48, 20);
		this.textBox3.TabIndex = 2;
		this.textBox3.Text = "";
		// 
		// textBox4
		// 
		this.textBox4.Location = new System.Drawing.Point(16, 120);
		this.textBox4.Name = "textBox4";
		this.textBox4.Size = new System.Drawing.Size(48, 20);
		this.textBox4.TabIndex = 3;
		this.textBox4.Text = "";
		// 
		// button1
		// 
		this.button1.FlatStyle = System.Windows.Forms.FlatStyle.System;
		this.button1.Location = new System.Drawing.Point(88, 72);
		this.button1.Name = "button1";
		this.button1.TabIndex = 4;
		this.button1.Text = "Read data";
		this.button1.Click += new System.EventHandler(this.button1_Click);
		// 
		// Form1
		// 
		this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
		this.ClientSize = new System.Drawing.Size(176, 150);
		this.Controls.Add(this.button1);
		this.Controls.Add(this.textBox4);
		this.Controls.Add(this.textBox3);
		this.Controls.Add(this.textBox2);
		this.Controls.Add(this.textBox1);
		this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
		this.MaximizeBox = false;
		this.MinimizeBox = false;
		this.Name = "Form1";
		this.Text = "Read textboxes";
		this.ResumeLayout(false);
	}
	#endregion

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

	private void button1_Click(object sender, System.EventArgs e)
	{
		double sum=0.0;

		sum=Read_textboxes(textBox1);        // Instead of four calls how we can do the same thing
		sum+=Read_textboxes(textBox2);      // using a for loop? For this example this is not a
		sum+=Read_textboxes(textBox3);      // problem but if the program has 700 different 
		sum+=Read_textboxes(textBox4);      // textboxes or 1000 comboboxes too many calls GKR...
		MessageBox.Show("Summary is " + sum.ToString(),"WOW!");
	}
	private double Read_textboxes (TextBox txtbox)
	{
		try
		{
        			return double.Parse(txtbox.Text,System.Globalization.NumberFormatInfo.InvariantInfo);
		}
		catch
		{
			return 0.0;
		}
	}
}
__________________

Last edited by MrSeanKon; 14th March, 2007 at 02:30 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 29th January, 2007, 10:23 AM
Gizmo's Avatar
Chief BBS Administrator
BassTeroids Champion, Global Player Champion, Aim & Fire Champion, Puzzle Maniax Champion, Othello Champion, Canyon Glider Champion, UFO Shoot Out Champion, Unicycle Challenge Champion, Zed Champion
 
Join Date: May 2003
Location: Webb City, Mo
Posts: 14,887
Send a message via ICQ to Gizmo Send a message via AIM to Gizmo Send a message via MSN to Gizmo Send a message via Yahoo to Gizmo Send a message via Skype™ to Gizmo

I believe the only way to do what you want is to enumerate the controls in the Controls container, looking for the controls that are of the textbox type. That's not a terribly efficient way of getting there, though.
__________________
Avatar and sig graphic by Pitch. Subscribers!
Ask about a custom graphic or avatar today!
 
Later,
Gizmo
Thermal Diode Mod and Direct-Die Water Block
8-Cheetah 18GiB U-2 SCSI
MegaRAID Enterprise 1500/128MiB
Samsung SyncMaster 955DF
TTGI/Superflower TTS-520 PSU
 

 
AOA Team filesAOA Team wcgAOA Team fah
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 5th February, 2007, 03:28 AM
MrSeanKon's Avatar
OcBible Creator
 
Join Date: June 2005
Location: Where the streets have no name
Posts: 766

Kinda confusing....
If I do this then is it easy to rewrite the source code?
__________________
GRAB overclocking -->OcBible v1.55 Guidemania v1.21
CARDGAMES-->Jack v1.17 Deck v1.13 Preference v1.20
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 12th February, 2007, 02:19 PM
Gizmo's Avatar
Chief BBS Administrator
BassTeroids Champion, Global Player Champion, Aim & Fire Champion, Puzzle Maniax Champion, Othello Champion, Canyon Glider Champion, UFO Shoot Out Champion, Unicycle Challenge Champion, Zed Champion
 
Join Date: May 2003
Location: Webb City, Mo
Posts: 14,887
Send a message via ICQ to Gizmo Send a message via AIM to Gizmo Send a message via MSN to Gizmo Send a message via Yahoo to Gizmo Send a message via Skype™ to Gizmo

TBH, the more I look at this, the less sense it makes to attack the problem the way you are asking. Here's why:

If you enumerate all the controls in the container, you could have to go through potentially thousands of controls. You'll have to look at the properties of each of those controls (the control type and the control name) to see if it is one of the ones you are interested in. I don't really see any gain for you in doing this.

MAYBE if you make the textbox controls part of another control container and put them in a group, so that you could enumerate the controls in that particular container rather than enumerating all the controls on the form, it would work. That's something you'd probably have to play with.
__________________
Avatar and sig graphic by Pitch. Subscribers!
Ask about a custom graphic or avatar today!
 
Later,
Gizmo
Thermal Diode Mod and Direct-Die Water Block
8-Cheetah 18GiB U-2 SCSI
MegaRAID Enterprise 1500/128MiB
Samsung SyncMaster 955DF
TTGI/Superflower TTS-520 PSU
 

 
AOA Team filesAOA Team wcgAOA Team fah
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 15th February, 2007, 05:40 AM
MrSeanKon's Avatar
OcBible Creator
 
Join Date: June 2005
Location: Where the streets have no name
Posts: 766

Mate

could you rewrite the above code and upload it here.
Please forgive me but I explained you at u2u.......
Thanks in advance.
__________________
GRAB overclocking -->OcBible v1.55 Guidemania v1.21
CARDGAMES-->Jack v1.17 Deck v1.13 Preference v1.20

Last edited by MrSeanKon; 15th February, 2007 at 05:41 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 28th February, 2007, 12:55 AM
Gizmo's Avatar
Chief BBS Administrator
BassTeroids Champion, Global Player Champion, Aim & Fire Champion, Puzzle Maniax Champion, Othello Champion, Canyon Glider Champion, UFO Shoot Out Champion, Unicycle Challenge Champion, Zed Champion
 
Join Date: May 2003
Location: Webb City, Mo
Posts: 14,887
Send a message via ICQ to Gizmo Send a message via AIM to Gizmo Send a message via MSN to Gizmo Send a message via Yahoo to Gizmo Send a message via Skype™ to Gizmo

The basic idea would be like this:

Assuming that you have a tab control, each tab on the tab control will itself also contain controls. Therefor, you iterate over each control on the tab, looking for the ones that are TextBox controls, like so:

Code:
	private void button1_Click(object sender, System.EventArgs e)
	{
		double sum=0.0;

		foreach (Control ctrl in this.tabpage1.Controls)
		{
			if(ctrl.GetType().FullName == "System.Windows.Forms.TextBox"
				sum=Read_textboxes(ctrl);
		}
		MessageBox.Show("Summary is " + sum.ToString(),"WOW!");
	}
	private double Read_textboxes (TextBox txtbox)
	{
		try
		{
        			return double.Parse(txtbox.Text,System.Globalization.NumberFormatInfo.InvariantInfo);
		}
		catch
		{
			return 0.0;
		}
	}
}
I hope this answers your question. As I said before, though, this could potentially be a horrid way of approaching the problem. It only really works if you can constrain the containing control so that it only contains textboxes. The easy way to do that would be to add a GroupBox control to the tab and place all of your TextBoxes inside that GroupBox.

Assuming you did the above, and placed all of the controls on tabpage1, inside a GroupBox called groupbox1, the code would look like this:

Code:
	private void button1_Click(object sender, System.EventArgs e)
	{
		double sum=0.0;

		foreach (Control ctrl in this.tabpage1.groupbox1.Controls)
		{
			if(ctrl.GetType().FullName == "System.Windows.Forms.TextBox"
				sum=Read_textboxes(ctrl);
		}
		MessageBox.Show("Summary is " + sum.ToString(),"WOW!");
	}
	private double Read_textboxes (TextBox txtbox)
	{
		try
		{
        			return double.Parse(txtbox.Text,System.Globalization.NumberFormatInfo.InvariantInfo);
		}
		catch
		{
			return 0.0;
		}
	}
}
So it is still the same idea, just one extra level of controls to reference.

Hope that helps.
__________________
Avatar and sig graphic by Pitch. Subscribers!
Ask about a custom graphic or avatar today!
 
Later,
Gizmo
Thermal Diode Mod and Direct-Die Water Block
8-Cheetah 18GiB U-2 SCSI
MegaRAID Enterprise 1500/128MiB
Samsung SyncMaster 955DF
TTGI/Superflower TTS-520 PSU
 

 
AOA Team filesAOA Team wcgAOA Team fah
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 28th February, 2007, 05:12 AM
MrSeanKon's Avatar
OcBible Creator
 
Join Date: June 2005
Location: Where the streets have no name
Posts: 766

Teacher the above code has some mistakes thus I rewrote it and new capabilities added.
Here it is:

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

namespace WindowsApplication1
{
	public class Form1 : System.Windows.Forms.Form
	{
		#region Form's variables
		private System.Windows.Forms.GroupBox groupBox1;
		private System.Windows.Forms.TextBox textBox1;
		private System.Windows.Forms.TextBox textBox2;
		private System.Windows.Forms.TextBox textBox3;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.Label label3;
		private System.Windows.Forms.Button btn_Add;
		private System.Windows.Forms.Button btn_Clear;
		private System.Windows.Forms.ComboBox comboBox1;
		private System.Windows.Forms.Label label4;
		private System.ComponentModel.Container components = null;
		#endregion

		#region Initialization and dispose
		public Form1()
		{
			InitializeComponent();
		}
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if (components != null) 
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}
		#endregion

		#region Windows Form Designer generated code
		private void InitializeComponent()
		{
			this.btn_Add = new System.Windows.Forms.Button();
			this.groupBox1 = new System.Windows.Forms.GroupBox();
			this.label3 = new System.Windows.Forms.Label();
			this.label2 = new System.Windows.Forms.Label();
			this.label1 = new System.Windows.Forms.Label();
			this.textBox1 = new System.Windows.Forms.TextBox();
			this.textBox2 = new System.Windows.Forms.TextBox();
			this.textBox3 = new System.Windows.Forms.TextBox();
			this.btn_Clear = new System.Windows.Forms.Button();
			this.comboBox1 = new System.Windows.Forms.ComboBox();
			this.label4 = new System.Windows.Forms.Label();
			this.groupBox1.SuspendLayout();
			this.SuspendLayout();
			// 
			// btn_Add
			// 
			this.btn_Add.FlatStyle = System.Windows.Forms.FlatStyle.System;
			this.btn_Add.Location = new System.Drawing.Point(48, 168);
			this.btn_Add.Name = "btn_Add";
			this.btn_Add.Size = new System.Drawing.Size(48, 23);
			this.btn_Add.TabIndex = 0;
			this.btn_Add.Text = "Add!";
			this.btn_Add.Click += new System.EventHandler(this.btn_Add_Click);
			// 
			// groupBox1
			// 
			this.groupBox1.Controls.Add(this.label3);
			this.groupBox1.Controls.Add(this.label2);					
			this.groupBox1.Controls.Add(this.label1);
			this.groupBox1.Controls.Add(this.textBox1);   // We must sort the added textboxes cos when the measurements=2
			this.groupBox1.Controls.Add(this.textBox2);   // the program reads and adds the first and the second textboxes
			this.groupBox1.Controls.Add(this.textBox3);
			this.groupBox1.Font = new System.Drawing.Font("Times New Roman", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(161)));
			this.groupBox1.ForeColor = System.Drawing.Color.Red;
			this.groupBox1.Location = new System.Drawing.Point(16, 16);
			this.groupBox1.Name = "groupBox1";
			this.groupBox1.Size = new System.Drawing.Size(128, 128);
			this.groupBox1.TabIndex = 1;
			this.groupBox1.TabStop = false;
			this.groupBox1.Text = "Card 1";
			// 
			// label3
			// 
			this.label3.AutoSize = true;
			this.label3.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(161)));
			this.label3.ForeColor = System.Drawing.SystemColors.ActiveCaption;
			this.label3.Location = new System.Drawing.Point(22, 98);
			this.label3.Name = "label3";
			this.label3.Size = new System.Drawing.Size(13, 18);
			this.label3.TabIndex = 5;
			this.label3.Text = "3";
			this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
			// 
			// label2
			// 
			this.label2.AutoSize = true;
			this.label2.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(161)));
			this.label2.ForeColor = System.Drawing.SystemColors.ActiveCaption;
			this.label2.Location = new System.Drawing.Point(22, 66);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(13, 18);
			this.label2.TabIndex = 4;
			this.label2.Text = "2";
			this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
			// 
			// label1
			// 
			this.label1.AutoSize = true;
			this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(161)));
			this.label1.ForeColor = System.Drawing.SystemColors.ActiveCaption;
			this.label1.Location = new System.Drawing.Point(22, 34);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(13, 18);
			this.label1.TabIndex = 3;
			this.label1.Text = "1";
			this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
			// 
			// textBox1
			// 
			this.textBox1.Font = new System.Drawing.Font("Times New Roman", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(161)));
			this.textBox1.Location = new System.Drawing.Point(40, 32);
			this.textBox1.Name = "textBox1";
			this.textBox1.Size = new System.Drawing.Size(64, 22);
			this.textBox1.TabIndex = 0;
			this.textBox1.Text = "";
			// 
			// textBox2
			// 
			this.textBox2.Font = new System.Drawing.Font("Tempus Sans ITC", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.textBox2.Location = new System.Drawing.Point(40, 64);
			this.textBox2.Name = "textBox2";
			this.textBox2.Size = new System.Drawing.Size(64, 24);
			this.textBox2.TabIndex = 1;
			this.textBox2.Text = "";
			// 
			// textBox3
			// 
			this.textBox3.Font = new System.Drawing.Font("Times New Roman", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(161)));
			this.textBox3.Location = new System.Drawing.Point(40, 96);
			this.textBox3.Name = "textBox3";
			this.textBox3.Size = new System.Drawing.Size(64, 22);
			this.textBox3.TabIndex = 2;
			this.textBox3.Text = "";
			// 
			// btn_Clear
			// 
			this.btn_Clear.FlatStyle = System.Windows.Forms.FlatStyle.System;
			this.btn_Clear.Location = new System.Drawing.Point(168, 168);
			this.btn_Clear.Name = "btn_Clear";
			this.btn_Clear.Size = new System.Drawing.Size(48, 23);
			this.btn_Clear.TabIndex = 2;
			this.btn_Clear.Text = "Clear!";
			this.btn_Clear.Click += new System.EventHandler(this.btn_Clear_Click);
			// 
			// comboBox1
			// 
			this.comboBox1.Font = new System.Drawing.Font("Calisto MT", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.comboBox1.Items.AddRange(new object[] {
														   "1",
														   "2",
														   "3"});
			this.comboBox1.Location = new System.Drawing.Point(184, 64);
			this.comboBox1.Name = "comboBox1";
			this.comboBox1.Size = new System.Drawing.Size(40, 25);
			this.comboBox1.TabIndex = 3;
			this.comboBox1.Text = "1";
			// 
			// label4
			// 
			this.label4.AutoSize = true;
			this.label4.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(161)));
			this.label4.ForeColor = System.Drawing.Color.FromArgb(((System.Byte)(0)), ((System.Byte)(192)), ((System.Byte)(0)));
			this.label4.Location = new System.Drawing.Point(160, 40);
			this.label4.Name = "label4";
			this.label4.Size = new System.Drawing.Size(97, 18);
			this.label4.TabIndex = 4;
			this.label4.Text = "Measurements";
			this.label4.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
			// 
			// Form1
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(266, 206);
			this.Controls.Add(this.label4);
			this.Controls.Add(this.comboBox1);
			this.Controls.Add(this.btn_Clear);
			this.Controls.Add(this.groupBox1);
			this.Controls.Add(this.btn_Add);
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
			this.MaximizeBox = false;
			this.Name = "Form1";
			this.Text = "Form1";
			this.groupBox1.ResumeLayout(false);
			this.ResumeLayout(false);
		}
		#endregion

		private double BAN=2310.2003;  // The BANNED value in OcBible

		[STAThread]
		static void Main() 
		{
			Application.EnableVisualStyles();
			Application.Run(new Form1());
		}
		/*********************************************** The read routine ***********************************************/
		private double Read_textboxes (TextBox txtbox)
		{
			try
			{
				return double.Parse(txtbox.Text,System.Globalization.NumberFormatInfo.InvariantInfo);
			}
			catch
			{
				return BAN;  
			}
		}
		/*********************************************** Perform addition ***********************************************/
		private void btn_Add_Click(object sender, System.EventArgs e)
		{
			double sum=BAN;
			bool flag=true;
			int measurements=1, index=1;
			
			try
			{
				measurements=int.Parse(comboBox1.Text);
			}
			catch
			{
				MessageBox.Show("The default measurements number is 1","Don't ZZZ",MessageBoxButtons.OK,MessageBoxIcon.Warning);
			}
			foreach (Control ctrl in this.groupBox1.Controls)
			{
				if (ctrl.GetType().FullName == "System.Windows.Forms.TextBox")
				{
					double read_value=Read_textboxes((TextBox) ctrl);
					if (index++ <= measurements)
					{
						if (read_value != BAN)
							sum+=read_value;
						else
						{
							MessageBox.Show("GKR no *****ing data in boxes","Wake up!!",MessageBoxButtons.OK,MessageBoxIcon.Error);
							flag=false;
						}
					}
				}
			}
			if (sum == BAN)
				MessageBox.Show("LOL enter something!","Wake up!!",MessageBoxButtons.OK,MessageBoxIcon.Error);
			else
			{
				string result=(sum-BAN).ToString(System.Globalization.NumberFormatInfo.InvariantInfo);
				if (flag)
					MessageBox.Show("summary is " + result,"Your",MessageBoxButtons.OK,MessageBoxIcon.Information);
				else
					MessageBox.Show("No output","Retry",MessageBoxButtons.OK,MessageBoxIcon.Warning);
			}
		}
		/********************************************** Clear the textboxes **********************************************/
		private void btn_Clear_Click(object sender, System.EventArgs e)
		{
			foreach (Control ctrl in this.groupBox1.Controls)
			{
				if (ctrl.GetType().FullName == "System.Windows.Forms.TextBox")
				{
					
					TextBox txtbox=(TextBox) ctrl;
					txtbox.Text="";
				}
				comboBox1.Text="1";
			}
		}
	}
}
__________________

Last edited by MrSeanKon; 2nd March, 2007 at 04:28 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 2nd March, 2007, 04:31 AM
MrSeanKon's Avatar
OcBible Creator
 
Join Date: June 2005
Location: Where the streets have no name
Posts: 766

However it is not optimized.
Imagine that the Card1 has many labels and textboxes.
Therefore the program will spend some extra time cos the foreach loop checks all controls (labels + textboxes) and compares if it the control is a label or a textbox.
This is not a big problem cos CPUs are very fast and the OcBible inputs are not millions.
BTW how we can optimize it????
Can we use e.g. the Tabindex property GKR I am impatient.....


P.S.
Am I a good student??????
Leet! http://www.geocities.com/seankoniaris/Smiles/leet.gif
__________________
GRAB overclocking -->OcBible v1.55 Guidemania v1.21
CARDGAMES-->Jack v1.17 Deck v1.13 Preference v1.20
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 2nd March, 2007, 11:39 AM
Gizmo's Avatar
Chief BBS Administrator
BassTeroids Champion, Global Player Champion, Aim & Fire Champion, Puzzle Maniax Champion, Othello Champion, Canyon Glider Champion, UFO Shoot Out Champion, Unicycle Challenge Champion, Zed Champion
 
Join Date: May 2003
Location: Webb City, Mo
Posts: 14,887
Send a message via ICQ to Gizmo Send a message via AIM to Gizmo Send a message via MSN to Gizmo Send a message via Yahoo to Gizmo Send a message via Skype™ to Gizmo

Quote:
Originally Posted by MrSeanKon
However it is not optimized.
Imagine that the Card1 has many labels and textboxes.
Therefore the program will spend some extra time cos the foreach loop checks all controls (labels + textboxes) and compares if it the control is a label or a textbox.
This is not a big problem cos CPUs are very fast and the OcBible inputs are not millions.
BTW how we can optimize it????
Can we use e.g. the Tabindex property GKR I am impatient.....
This is exactly why you should place the relevant controls in their own group box, to enable you to reduce the amount of controls you have to iterate over. You can have group boxes inside other group boxes as well.....get the idea?

Quote:
Originally Posted by MrSeanKon
P.S.
Am I a good student??????
Leet! http://www.geocities.com/seankoniaris/Smiles/leet.gif
You are doing just fine. At this point, you probably have a better knowledge of C# and .NET than I do. I just know programming.
__________________
Avatar and sig graphic by Pitch. Subscribers!
Ask about a custom graphic or avatar today!
 
Later,
Gizmo
Thermal Diode Mod and Direct-Die Water Block
8-Cheetah 18GiB U-2 SCSI
MegaRAID Enterprise 1500/128MiB
Samsung SyncMaster 955DF
TTGI/Superflower TTS-520 PSU
 

 
AOA Team filesAOA Team wcgAOA Team fah
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 6th March, 2007, 04:35 AM
MrSeanKon's Avatar
OcBible Creator
 
Join Date: June 2005
Location: Where the streets have no name
Posts: 766

gizmo the next code is based on the above but I also changed the tabindex values for textboxes and labels.
Some of them have the same value; anyway the program is OK.


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

namespace WindowsApplication1
{
	public class Form1 : System.Windows.Forms.Form
	{
		#region Form's variables
		private System.Windows.Forms.GroupBox groupBox1;
		private System.Windows.Forms.TextBox textBox1;
		private System.Windows.Forms.TextBox textBox2;
		private System.Windows.Forms.TextBox textBox3;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.Label label3;
		private System.Windows.Forms.Button btn_Add;
		private System.Windows.Forms.Button btn_Clear;
		private System.Windows.Forms.ComboBox comboBox1;
		private System.Windows.Forms.Label label4;
		private System.ComponentModel.Container components = null;
		#endregion

		#region Initialization and dispose
		public Form1()
		{
			InitializeComponent();
		}
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if (components != null) 
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}
		#endregion

		#region Windows Form Designer generated code
		private void InitializeComponent()
		{
			this.btn_Add = new System.Windows.Forms.Button();
			this.groupBox1 = new System.Windows.Forms.GroupBox();
			this.label3 = new System.Windows.Forms.Label();
			this.label2 = new System.Windows.Forms.Label();
			this.label1 = new System.Windows.Forms.Label();
			this.textBox1 = new System.Windows.Forms.TextBox();
			this.textBox2 = new System.Windows.Forms.TextBox();
			this.textBox3 = new System.Windows.Forms.TextBox();
			this.btn_Clear = new System.Windows.Forms.Button();
			this.comboBox1 = new System.Windows.Forms.ComboBox();
			this.label4 = new System.Windows.Forms.Label();
			this.groupBox1.SuspendLayout();
			this.SuspendLayout();
			// 
			// btn_Add
			// 
			this.btn_Add.FlatStyle = System.Windows.Forms.FlatStyle.System;
			this.btn_Add.Location = new System.Drawing.Point(48, 168);
			this.btn_Add.Name = "btn_Add";
			this.btn_Add.Size = new System.Drawing.Size(48, 23);
			this.btn_Add.TabIndex = 0;
			this.btn_Add.Text = "Add!";
			this.btn_Add.Click += new System.EventHandler(this.btn_Add_Click);
			// 
			// groupBox1
			// 
			this.groupBox1.Controls.Add(this.label3);
			this.groupBox1.Controls.Add(this.label2);
			this.groupBox1.Controls.Add(this.label1);
			this.groupBox1.Controls.Add(this.textBox1);
			this.groupBox1.Controls.Add(this.textBox2);
			this.groupBox1.Controls.Add(this.textBox3);
			this.groupBox1.Font = new System.Drawing.Font("Times New Roman", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(161)));
			this.groupBox1.ForeColor = System.Drawing.Color.Red;
			this.groupBox1.Location = new System.Drawing.Point(16, 16);
			this.groupBox1.Name = "groupBox1";
			this.groupBox1.Size = new System.Drawing.Size(128, 128);
			this.groupBox1.TabIndex = 1;
			this.groupBox1.TabStop = false;
			this.groupBox1.Text = "Card 1";
			// 
			// label3
			// 
			this.label3.AutoSize = true;
			this.label3.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(161)));
			this.label3.ForeColor = System.Drawing.SystemColors.ActiveCaption;
			this.label3.Location = new System.Drawing.Point(22, 98);
			this.label3.Name = "label3";
			this.label3.Size = new System.Drawing.Size(13, 18);
			this.label3.TabIndex = 33;
			this.label3.Text = "3";
			this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
			// 
			// label2
			// 
			this.label2.AutoSize = true;
			this.label2.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(161)));
			this.label2.ForeColor = System.Drawing.SystemColors.ActiveCaption;
			this.label2.Location = new System.Drawing.Point(22, 66);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(13, 18);
			this.label2.TabIndex = 4;
			this.label2.Text = "2";
			this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
			// 
			// label1
			// 
			this.label1.AutoSize = true;
			this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(161)));
			this.label1.ForeColor = System.Drawing.SystemColors.ActiveCaption;
			this.label1.Location = new System.Drawing.Point(22, 34);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(13, 18);
			this.label1.TabIndex = 32;
			this.label1.Text = "1";
			this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
			// 
			// textBox1
			// 
			this.textBox1.Font = new System.Drawing.Font("Times New Roman", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(161)));
			this.textBox1.Location = new System.Drawing.Point(40, 32);
			this.textBox1.Name = "textBox1";
			this.textBox1.Size = new System.Drawing.Size(64, 22);
			this.textBox1.TabIndex = 32;
			this.textBox1.Text = "";
			// 
			// textBox2
			// 
			this.textBox2.Font = new System.Drawing.Font("Times New Roman", 9.75F, System.Drawing.FontStyle.Bold);
			this.textBox2.Location = new System.Drawing.Point(40, 64);
			this.textBox2.Name = "textBox2";
			this.textBox2.Size = new System.Drawing.Size(64, 22);
			this.textBox2.TabIndex = 33;
			this.textBox2.Text = "";
			// 
			// textBox3
			// 
			this.textBox3.Font = new System.Drawing.Font("Times New Roman", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(161)));
			this.textBox3.Location = new System.Drawing.Point(40, 96);
			this.textBox3.Name = "textBox3";
			this.textBox3.Size = new System.Drawing.Size(64, 22);
			this.textBox3.TabIndex = 33;
			this.textBox3.Text = "";
			// 
			// btn_Clear
			// 
			this.btn_Clear.FlatStyle = System.Windows.Forms.FlatStyle.System;
			this.btn_Clear.Location = new System.Drawing.Point(168, 168);
			this.btn_Clear.Name = "btn_Clear";
			this.btn_Clear.Size = new System.Drawing.Size(48, 23);
			this.btn_Clear.TabIndex = 2;
			this.btn_Clear.Text = "Clear!";
			this.btn_Clear.Click += new System.EventHandler(this.btn_Clear_Click);
			// 
			// comboBox1
			// 
			this.comboBox1.Font = new System.Drawing.Font("Calisto MT", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.comboBox1.Items.AddRange(new object[] {
														   "1",
														   "2",
														   "3"});
			this.comboBox1.Location = new System.Drawing.Point(184, 64);
			this.comboBox1.Name = "comboBox1";
			this.comboBox1.Size = new System.Drawing.Size(40, 25);
			this.comboBox1.TabIndex = 3;
			this.comboBox1.Text = "1";
			// 
			// label4
			// 
			this.label4.AutoSize = true;
			this.label4.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(161)));
			this.label4.ForeColor = System.Drawing.Color.FromArgb(((System.Byte)(0)), ((System.Byte)(192)), ((System.Byte)(0)));
			this.label4.Location = new System.Drawing.Point(160, 40);
			this.label4.Name = "label4";
			this.label4.Size = new System.Drawing.Size(97, 18);
			this.label4.TabIndex = 4;
			this.label4.Text = "Measurements";
			this.label4.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
			// 
			// Form1
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(266, 206);
			this.Controls.Add(this.label4);
			this.Controls.Add(this.comboBox1);
			this.Controls.Add(this.btn_Clear);
			this.Controls.Add(this.groupBox1);
			this.Controls.Add(this.btn_Add);
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
			this.MaximizeBox = false;
			this.Name = "Form1";
			this.Text = "Form1";
			this.groupBox1.ResumeLayout(false);
			this.ResumeLayout(false);
		}
		#endregion

		private double BAN=2310.2003;  // The BANNED value in OcBible

		[STAThread]
		static void Main() 
		{
			Application.EnableVisualStyles();
			Application.Run(new Form1());
		}
		/*********************************************** The read routine ***********************************************/
		private double Read_textboxes (TextBox txtbox)
		{
			try
			{
				return double.Parse(txtbox.Text,System.Globalization.NumberFormatInfo.InvariantInfo);
			}
			catch
			{
				return BAN;  
			}
		}
		/*********************************************** Perform addition ***********************************************/
		private void btn_Add_Click(object sender, System.EventArgs e)
		{
			double sum=BAN;
			bool flag=true;
			int measurements=1, index=1;
			
			try
			{
				measurements=int.Parse(comboBox1.Text);
			}
			catch
			{
				MessageBox.Show("The default measurements number is 1","Don't ZZZ",MessageBoxButtons.OK,MessageBoxIcon.Warning);
			}
			foreach (Control ctrl in this.groupBox1.Controls)
			{
				if (ctrl.GetType().FullName == "System.Windows.Forms.TextBox")
				{
					double read_value=Read_textboxes((TextBox) ctrl);
					if (index++ <= measurements)
					{
						if (read_value != BAN)
							sum+=read_value;
						else
						{
							MessageBox.Show("GKR no wrong data in boxes","Wake up!!",MessageBoxButtons.OK,MessageBoxIcon.Error);
							flag=false;
						}
					}
				}
			}
			if (sum == BAN)
				MessageBox.Show("LOL enter something!","Wake up!!",MessageBoxButtons.OK,MessageBoxIcon.Error);
			else
			{
				string result=(sum-BAN).ToString(System.Globalization.NumberFormatInfo.InvariantInfo);
				if (flag)
					MessageBox.Show("summary is " + result,"Your",MessageBoxButtons.OK,MessageBoxIcon.Information);
				else
					MessageBox.Show("No output","Retry",MessageBoxButtons.OK,MessageBoxIcon.Warning);
			}
		}
		/********************************************** Clear the textboxes **********************************************/
		private void btn_Clear_Click(object sender, System.EventArgs e)
		{
			foreach (Control ctrl in this.groupBox1.Controls)
			{
				if (ctrl.GetType().FullName == "System.Windows.Forms.TextBox")
				{
					
					TextBox txtbox=(TextBox) ctrl;
					txtbox.Text="";
				}
				comboBox1.Text="1";
			}
		}
	}
}
__________________

Last edited by MrSeanKon; 13th March, 2007 at 02:39 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #11 (permalink)  
Old 13th March, 2007, 02:40 AM
MrSeanKon's Avatar
OcBible Creator
 
Join Date: June 2005
Location: Where the streets have no name
Posts: 766

However if we enter all textboxes (only the textboxes) in a panel (which is inside of groupbox) then no waste time and we can remove the if statement in foreach loop.

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

namespace WindowsApplication1
{
	public class Form1 : System.Windows.Forms.Form
	{
		#region Form's variables
		private System.Windows.Forms.GroupBox groupBox1;
		private System.Windows.Forms.TextBox textBox1;
		private System.Windows.Forms.TextBox textBox2;
		private System.Windows.Forms.TextBox textBox3;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.Label label3;
		private System.Windows.Forms.Button btn_Add;
		private System.Windows.Forms.Button btn_Clear;
		private System.Windows.Forms.ComboBox comboBox1;
		private System.Windows.Forms.Label label4;
		private System.Windows.Forms.Panel panel1;
		private System.ComponentModel.Container components = null;
		#endregion

		#region Initialization and dispose
		public Form1()
		{
			InitializeComponent();
		}
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if (components != null) 
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}
		#endregion

		#region Windows Form Designer generated code
		private void InitializeComponent()
		{
			this.btn_Add = new System.Windows.Forms.Button();
			this.groupBox1 = new System.Windows.Forms.GroupBox();
			this.label3 = new System.Windows.Forms.Label();
			this.label2 = new System.Windows.Forms.Label();
			this.label1 = new System.Windows.Forms.Label();
			this.textBox1 = new System.Windows.Forms.TextBox();
			this.textBox2 = new System.Windows.Forms.TextBox();
			this.textBox3 = new System.Windows.Forms.TextBox();
			this.btn_Clear = new System.Windows.Forms.Button();
			this.comboBox1 = new System.Windows.Forms.ComboBox();
			this.label4 = new System.Windows.Forms.Label();
			this.panel1 = new System.Windows.Forms.Panel();
			this.groupBox1.SuspendLayout();
			this.panel1.SuspendLayout();
			this.SuspendLayout();
			// 
			// btn_Add
			// 
			this.btn_Add.Cursor = System.Windows.Forms.Cursors.Hand;
			this.btn_Add.FlatStyle = System.Windows.Forms.FlatStyle.System;
			this.btn_Add.Location = new System.Drawing.Point(48, 168);
			this.btn_Add.Name = "btn_Add";
			this.btn_Add.Size = new System.Drawing.Size(48, 23);
			this.btn_Add.TabIndex = 0;
			this.btn_Add.Text = "Add!";
			this.btn_Add.Click += new System.EventHandler(this.btn_Add_Click);
			// 
			// groupBox1
			// 
			this.groupBox1.Controls.Add(this.panel1);
			this.groupBox1.Controls.Add(this.label3);
			this.groupBox1.Controls.Add(this.label2);
			this.groupBox1.Controls.Add(this.label1);
			this.groupBox1.Font = new System.Drawing.Font("Times New Roman", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(161)));
			this.groupBox1.ForeColor = System.Drawing.Color.Red;
			this.groupBox1.Location = new System.Drawing.Point(16, 16);
			this.groupBox1.Name = "groupBox1";
			this.groupBox1.Size = new System.Drawing.Size(128, 128);
			this.groupBox1.TabIndex = 1;
			this.groupBox1.TabStop = false;
			this.groupBox1.Text = "Card 1";
			// 
			// label3
			// 
			this.label3.AutoSize = true;
			this.label3.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(161)));
			this.label3.ForeColor = System.Drawing.SystemColors.ActiveCaption;
			this.label3.Location = new System.Drawing.Point(22, 98);
			this.label3.Name = "label3";
			this.label3.Size = new System.Drawing.Size(13, 18);
			this.label3.TabIndex = 5;
			this.label3.Text = "3";
			this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
			// 
			// label2
			// 
			this.label2.AutoSize = true;
			this.label2.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(161)));
			this.label2.ForeColor = System.Drawing.SystemColors.ActiveCaption;
			this.label2.Location = new System.Drawing.Point(22, 66);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(13, 18);
			this.label2.TabIndex = 4;
			this.label2.Text = "2";
			this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
			// 
			// label1
			// 
			this.label1.AutoSize = true;
			this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(161)));
			this.label1.ForeColor = System.Drawing.SystemColors.ActiveCaption;
			this.label1.Location = new System.Drawing.Point(22, 34);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(13, 18);
			this.label1.TabIndex = 3;
			this.label1.Text = "1";
			this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
			// 
			// textBox1
			// 
			this.textBox1.Font = new System.Drawing.Font("Times New Roman", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(161)));
			this.textBox1.Location = new System.Drawing.Point(0, 8);
			this.textBox1.Name = "textBox1";
			this.textBox1.Size = new System.Drawing.Size(64, 22);
			this.textBox1.TabIndex = 0;
			this.textBox1.Text = "";
			// 
			// textBox2
			// 
			this.textBox2.Font = new System.Drawing.Font("Times New Roman", 9.75F, System.Drawing.FontStyle.Bold);
			this.textBox2.Location = new System.Drawing.Point(0, 40);
			this.textBox2.Name = "textBox2";
			this.textBox2.Size = new System.Drawing.Size(64, 22);
			this.textBox2.TabIndex = 1;
			this.textBox2.Text = "";
			// 
			// textBox3
			// 
			this.textBox3.Font = new System.Drawing.Font("Times New Roman", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(161)));
			this.textBox3.Location = new System.Drawing.Point(0, 72);
			this.textBox3.Name = "textBox3";
			this.textBox3.Size = new System.Drawing.Size(64, 22);
			this.textBox3.TabIndex = 2;
			this.textBox3.Text = "";
			// 
			// btn_Clear
			// 
			this.btn_Clear.Cursor = System.Windows.Forms.Cursors.Hand;
			this.btn_Clear.FlatStyle = System.Windows.Forms.FlatStyle.System;
			this.btn_Clear.Location = new System.Drawing.Point(168, 168);
			this.btn_Clear.Name = "btn_Clear";
			this.btn_Clear.Size = new System.Drawing.Size(48, 23);
			this.btn_Clear.TabIndex = 2;
			this.btn_Clear.Text = "Clear!";
			this.btn_Clear.Click += new System.EventHandler(this.btn_Clear_Click);
			// 
			// comboBox1
			// 
			this.comboBox1.Font = new System.Drawing.Font("Calisto MT", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.comboBox1.Items.AddRange(new object[] {
														   "1",
														   "2",
														   "3"});
			this.comboBox1.Location = new System.Drawing.Point(176, 96);
			this.comboBox1.Name = "comboBox1";
			this.comboBox1.Size = new System.Drawing.Size(40, 25);
			this.comboBox1.TabIndex = 3;
			this.comboBox1.Text = "1";
			// 
			// label4
			// 
			this.label4.AutoSize = true;
			this.label4.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(161)));
			this.label4.ForeColor = System.Drawing.Color.FromArgb(((System.Byte)(0)), ((System.Byte)(192)), ((System.Byte)(0)));
			this.label4.Location = new System.Drawing.Point(152, 72);
			this.label4.Name = "label4";
			this.label4.Size = new System.Drawing.Size(97, 18);
			this.label4.TabIndex = 4;
			this.label4.Text = "Measurements";
			this.label4.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
			// 
			// panel1
			// 
			this.panel1.Controls.Add(this.textBox1);
			this.panel1.Controls.Add(this.textBox2);
			this.panel1.Controls.Add(this.textBox3);
			this.panel1.Location = new System.Drawing.Point(38, 24);
			this.panel1.Name = "panel1";
			this.panel1.Size = new System.Drawing.Size(72, 96);
			this.panel1.TabIndex = 6;
			// 
			// Form1
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(258, 206);
			this.Controls.Add(this.label4);
			this.Controls.Add(this.comboBox1);
			this.Controls.Add(this.btn_Clear);
			this.Controls.Add(this.groupBox1);
			this.Controls.Add(this.btn_Add);
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
			this.MaximizeBox = false;
			this.Name = "Form1";
			this.Text = "Form1";
			this.groupBox1.ResumeLayout(false);
			this.panel1.ResumeLayout(false);
			this.ResumeLayout(false);
		}
		#endregion

		double BAN=2310.2003;  // The BANNED value in OcBible

		[STAThread]
		static void Main() 
		{
			Application.EnableVisualStyles();
			Application.Run(new Form1());
		}
		/*********************************************** The read routine ***********************************************/
		private double Read_textboxes (TextBox txtbox)
		{
			try
			{
				return double.Parse(txtbox.Text,System.Globalization.NumberFormatInfo.InvariantInfo);
			}
			catch
			{
				return BAN;  
			}
		}
		/*********************************************** Perform addition ***********************************************/
		private void btn_Add_Click(object sender, System.EventArgs e)
		{
			double sum=BAN;
			bool flag=true;
			int measurements=1, index=1;
			
			try
			{
				measurements=int.Parse(comboBox1.Text);
			}
			catch
			{
				MessageBox.Show("The default measurements number is 1","Don't ZZZ",MessageBoxButtons.OK,MessageBoxIcon.Warning);
			}
			foreach (Control ctrl in this.panel1.Controls)
			{
				double read_value=Read_textboxes((TextBox) ctrl);
				if (index++ <= measurements)
				{
					if (read_value != BAN)
						sum+=read_value;
					else
					{
						MessageBox.Show("GKR no wrong data in boxes","Wake up!!",MessageBoxButtons.OK,MessageBoxIcon.Error);
						flag=false;
					}
				}
			}
			if (sum == BAN)
				MessageBox.Show("LOL enter something!","Wake up!!",MessageBoxButtons.OK,MessageBoxIcon.Error);
			else
			{
				string result=(sum-BAN).ToString(System.Globalization.NumberFormatInfo.InvariantInfo);
				if (flag)
					MessageBox.Show("summary is " + result,"Your",MessageBoxButtons.OK,MessageBoxIcon.Information);
				else
					MessageBox.Show("No output","Retry",MessageBoxButtons.OK,MessageBoxIcon.Warning);
			}
		}
		/********************************************** Clear the textboxes **********************************************/
		private void btn_Clear_Click(object sender, System.EventArgs e)
		{
			foreach (Control ctrl in this.panel1.Controls)
			{
				TextBox txtbox=(TextBox) ctrl;
				txtbox.Text="";
			}
			comboBox1.Text="1";
		}
	}
}
IMHO I will use this idea instead of tabindex I cannot imagine a case which two different textboxes have the same tabindex value GKR......
Moreover when I add or remove some textboxes I must check some tabindexes.
What's your opinion?
__________________
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #12 (permalink)  
Old 13th March, 2007, 01:46 PM
Gizmo's Avatar
Chief BBS Administrator
BassTeroids Champion, Global Player Champion, Aim & Fire Champion, Puzzle Maniax Champion, Othello Champion, Canyon Glider Champion, UFO Shoot Out Champion, Unicycle Challenge Champion, Zed Champion
 
Join Date: May 2003
Location: Webb City, Mo
Posts: 14,887
Send a message via ICQ to Gizmo Send a message via AIM to Gizmo Send a message via MSN to Gizmo Send a message via Yahoo to Gizmo Send a message via Skype™ to Gizmo

Quote:
Originally Posted by MrSeanKon
However if we enter all textboxes (only the textboxes) in a panel (which is inside of groupbox) then no waste time and we can remove the if statement in foreach loop.

IMHO I will use this idea instead of tabindex I cannot imagine a case which two different textboxes have the same tabindex value GKR......
Moreover when I add or remove some textboxes I must check some tabindexes.
What's your opinion?
This is the reason I suggested using the groupbox approach; it just makes life a lot simpler than using tabindexes or some such.
__________________
Avatar and sig graphic by Pitch. Subscribers!
Ask about a custom graphic or avatar today!
 
Later,
Gizmo
Thermal Diode Mod and Direct-Die Water Block
8-Cheetah 18GiB U-2 SCSI
MegaRAID Enterprise 1500/128MiB
Samsung SyncMaster 955DF
TTGI/Superflower TTS-520 PSU
 

 
AOA Team filesAOA Team wcgAOA Team fah
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #13 (permalink)  
Old 14th March, 2007, 02:32 AM
MrSeanKon's Avatar
OcBible Creator
 
Join Date: June 2005
Location: Where the streets have no name
Posts: 766

Thus we agree gizmo that this is the one of the best solutions.
Moreover two UK programmers posted some other tricks.
I will play later with the code.
__________________
GRAB overclocking -->OcBible v1.55 Guidemania v1.21
CARDGAMES-->Jack v1.17 Deck v1.13 Preference v1.20

Last edited by MrSeanKon; 14th March, 2007 at 02:38 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #14 (permalink)  
Old 19th March, 2007, 07:00 PM
Member
 
Join Date: March 2007
Posts: 2

Hi guys.

I think i have a better and faster solution than crawling into controls.

It's so simple as create a List<TextBox> at the program entry point, scan all the controls for textboxes and add them to the list. After that you will have a reference to all your textboxes into the list and enumerate the items of a list is faster than doing it into a control container.

And if you want to have faster acces to individual elements by key then don't use the List class, use a SortedList or a Dictionary and then you can use the key given to the element or enumerate the values at the Value property.

Hope it helps.

P.D.: sorry for my bad english
__________________
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #15 (permalink)  
Old 21st March, 2007, 02:19 AM
MrSeanKon's Avatar
OcBible Creator
 
Join Date: June 2005
Location: Where the streets have no name
Posts: 766

Thanks for your reply.
Cos I am being f_cked up with Micro$oft products I have no time to maintain and tweak this code.
I'll do this later cos I must decide the next steps.
If you can upload source code it will be appreciated.
BTW welcome to Aoaforums.
__________________
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #16 (permalink)  
Old 30th March, 2007, 06:08 AM
Member
 
Join Date: March 2007
Posts: 2

Hello

Here is the code with the metod i exposed on the previous post:

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

namespace testLoop
{
    public class Form1 : Form
    {
        private List<TextBox> textBoxesList = new List<TextBox>();
        #region Código generado por el Diseñador de Windows Forms
        private TextBox textBox1;
        private TextBox textBox2;
        private TextBox textBox3;
        private TextBox textBox4;
        private TextBox textBox5;
        private TextBox textBox6;
        private TextBox textBox7;
        private TextBox textBox8;
        private TextBox textBox9;
        private Button button1;
        private Button button2;
        /// <summary>
        /// Variable del diseñador requerida.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// Limpiar los recursos que se estén utilizando.
        /// </summary>
        /// <param name="disposing">true si los recursos administrados se deben eliminar; false en caso contrario, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        /// <summary>
        /// Método necesario para admitir el Diseñador. No se puede modificar
        /// el contenido del método con el editor de código.
        /// </summary>
        private void InitializeComponent()
        {
            this.textBox1 = new System.Windows.Forms.TextBox();
            this.textBox2 = new System.Windows.Forms.TextBox();
            this.textBox3 = new System.Windows.Forms.TextBox();
            this.textBox4 = new System.Windows.Forms.TextBox();
            this.textBox5 = new System.Windows.Forms.TextBox();
            this.textBox6 = new System.Windows.Forms.TextBox();
            this.textBox7 = new System.Windows.Forms.TextBox();
            this.textBox8 = new System.Windows.Forms.TextBox();
            this.textBox9 = new System.Windows.Forms.TextBox();
            this.button1 = new System.Windows.Forms.Button();
            this.button2 = new System.Windows.Forms.Button();
            this.SuspendLayout();
            // 
            // textBox1
            // 
            this.textBox1.Location = new System.Drawing.Point(12, 12);
            this.textBox1.Name = "textBox1";
            this.textBox1.Size = new System.Drawing.Size(315, 20);
            this.textBox1.TabIndex = 0;
            // 
            // textBox2
            // 
            this.textBox2.Location = new System.Drawing.Point(12, 38);
            this.textBox2.Name = "textBox2";
            this.textBox2.Size = new System.Drawing.Size(315, 20);
            this.textBox2.TabIndex = 1;
            // 
            // textBox3
            // 
            this.textBox3.Location = new System.Drawing.Point(12, 64);
            this.textBox3.Name = "textBox3";
            this.textBox3.Size = new System.Drawing.Size(315, 20);
            this.textBox3.TabIndex = 2;
            // 
            // textBox4
            // 
            this.textBox4.Location = new System.Drawing.Point(12, 90);
            this.textBox4.Name = "textBox4";
            this.textBox4.Size = new System.Drawing.Size(315, 20);
            this.textBox4.TabIndex = 3;
            // 
            // textBox5
            // 
            this.textBox5.Location = new System.Drawing.Point(12, 116);
            this.textBox5.Name = "textBox5";
            this.textBox5.Size = new System.Drawing.Size(315, 20);
            this.textBox5.TabIndex = 4;
            // 
            // textBox6
            // 
            this.textBox6.Location = new System.Drawing.Point(12, 142);
            this.textBox6.Name = "textBox6";
            this.textBox6.Size = new System.Drawing.Size(315, 20);
            this.textBox6.TabIndex = 5;
            // 
            // textBox7
            // 
            this.textBox7.Location = new System.Drawing.Point(12, 168);
            this.textBox7.Name = "textBox7";
            this.textBox7.Size = new System.Drawing.Size(315, 20);
            this.textBox7.TabIndex = 6;
            // 
            // textBox8
            // 
            this.textBox8.Location = new System.Drawing.Point(12, 194);
            this.textBox8.Name = "textBox8";
            this.textBox8.Size = new System.Drawing.Size(315, 20);
            this.textBox8.TabIndex = 7;
            // 
            // textBox9
            // 
            this.textBox9.Location = new System.Drawing.Point(12, 220);
            this.textBox9.Name = "textBox9";
            this.textBox9.Size = new System.Drawing.Size(315, 20);
            this.textBox9.TabIndex = 8;
            // 
            // button1
            // 
            this.button1.Location = new System.Drawing.Point(12, 246);
            this.button1.Name = "button1";
            this.button1.Size = new System.Drawing.Size(315, 25);
            this.button1.TabIndex = 9;
            this.button1.Text = "Read textBoxes";
            this.button1.UseVisualStyleBackColor = true;
            this.button1.Click += new System.EventHandler(this.button1_Click);
            // 
            // button2
            // 
            this.button2.Location = new System.Drawing.Point(12, 277);
            this.button2.Name = "button2";
            this.button2.Size = new System.Drawing.Size(315, 25);
            this.button2.TabIndex = 10;
            this.button2.Text = "Write textBoxes";
            this.button2.UseVisualStyleBackColor = true;
            this.button2.Click += new System.EventHandler(this.button2_Click);
            // 
            // Form1
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(339, 313);
            this.Controls.Add(this.button2);
            this.Controls.Add(this.button1);
            this.Controls.Add(this.textBox9);
            this.Controls.Add(this.textBox8);
            this.Controls.Add(this.textBox7);
            this.Controls.Add(this.textBox6);
            this.Controls.Add(this.textBox5);
            this.Controls.Add(this.textBox4);
            this.Controls.Add(this.textBox3);
            this.Controls.Add(this.textBox2);
            this.Controls.Add(this.textBox1);
            this.Name = "Form1";
            this.Text = "TextBox List";
            this.Load += new System.EventHandler(this.Form1_Load);
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        #endregion
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            foreach (Control c in this.Controls)
            {

                try {

                    textBoxesList.Add((TextBox)c);
                
                }
                catch { }
            
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string message = "";

            for (int buc = 0; buc < textBoxesList.Count; buc++)
                message += "TextBox number " + buc.ToString() + ": " + textBoxesList[buc].Text + "\r\n";

            MessageBox.Show(message);
        }

        private void button2_Click(object sender, EventArgs e)
        {
            for (int buc = 0; buc < textBoxesList.Count; buc++)
                textBoxesList[buc].Text = "C# Rulez, i will say this " + (buc + 1).ToString() + (buc > 0 ? " times" : " time");
        }

    }
}
if an example with the SortedList method is needed ask for it, i will post it here.

Hope it helps

P.D. Sorry for my bad english, i'm Spanish
__________________
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #17 (permalink)  
Old 30th March, 2007, 09:27 AM
Gizmo's Avatar
Chief BBS Administrator
BassTeroids Champion, Global Player Champion, Aim & Fire Champion, Puzzle Maniax Champion, Othello Champion, Canyon Glider Champion, UFO Shoot Out Champion, Unicycle Challenge Champion, Zed Champion
 
Join Date: May 2003
Location: Webb City, Mo
Posts: 14,887
Send a message via ICQ to Gizmo Send a message via AIM to Gizmo Send a message via MSN to Gizmo Send a message via Yahoo to Gizmo Send a message via Skype™ to Gizmo

Quote:
Originally Posted by Gusman
P.D. Sorry for my bad english, i'm Spanish
Don't worry about your English. We speak programming in this forum anyway.
__________________
Avatar and sig graphic by Pitch. Subscribers!
Ask about a custom graphic or avatar today!
 
Later,
Gizmo
Thermal Diode Mod and Direct-Die Water Block
8-Cheetah 18GiB U-2 SCSI
MegaRAID Enterprise 1500/128MiB
Samsung SyncMaster 955DF
TTGI/Superflower TTS-520 PSU
 

 
AOA Team filesAOA Team wcgAOA Team fah
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #18 (permalink)  
Old 3rd April, 2007, 05:26 AM
MrSeanKon's Avatar
OcBible Creator
 
Join Date: June 2005
Location: Where the streets have no name
Posts: 766

WOW man=Gusman thanks for posting.
I also don't speak perfect English cos I am European like you (I live in Greece).
At least we can communicate.
By the way you can translate the OcBible in Spanish.
I am getting busy these days so I will check your code other day.
Thanks for your effort.
__________________
GRAB overclocking -->OcBible v1.55 Guidemania v1.21
CARDGAMES-->Jack v1.17 Deck v1.13 Preference v1.20
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Hibernation loop in 2k videobruce OS, Software, Firmware, and BIOS 3 10th October, 2005 11:24 AM
FAH client gets into endless loop drow_elf Samuknow's AOA FOLDING@HOME Team 7 10th August, 2004 04:49 PM
system idle loop shamrock_uk General Hardware Discussion 3 17th October, 2003 11:57 PM
reboot loop mrands2 EPoX MotherBoards 3 9th May, 2003 04:57 PM
Infinite Loop possible cause... Orbit General Hardware Discussion 3 23rd August, 2002 10:11 AM


All times are GMT -5. The time now is 07:07 PM.


Copyright ©2001 - 2009, AOA Forums

Search Engine Friendly URLs by vBSEO 3.3.0