View Single Post
  #7 (permalink)  
Old 28th February, 2007, 05:12 AM
MrSeanKon's Avatar
MrSeanKon MrSeanKon is offline
OcBible Creator
 
Join Date: June 2005
Location: Where the streets have no name
Posts: 768

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.
Reply With Quote