Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

How To Use Gofunction In C#

combobox

  • Please log in to reply
3 replies to this topic

#1 percis

percis

    CC Resident

  • Advanced Member
  • PipPipPipPip
  • 72 posts
  • Programming Language:C
  • Learning:C#, (Visual) Basic

Posted 04 July 2012 - 09:09 PM

private void comboBox42_SelectedIndexChanged(object sender, EventArgs e)
	 {
		 if (comboBox42.Text == "Fluorescent Light")
		 {
			 comboBox12.Items.Clear();
			 label67.Text = "1";
			 comboBox12.Items.Add(22);
			 comboBox12.Items.Add(32);
			 comboBox12.Items.Add(48);			
		 }
		
		 else if (comboBox42.Text == "Fridge")
		 {
			 comboBox12.Items.Clear();
			 label67.Text = "2";
			 comboBox12.Items.Add(1000);
			 comboBox12.Items.Add(1700);
			 comboBox12.Items.Add(2400);
		 }
		 else if (comboBox42.Text == "Air Conditioner")
		 {
			 comboBox12.Items.Clear();
			 label67.Text = "4";
			 comboBox12.Items.Add(800);
			 comboBox12.Items.Add(1000);
			 comboBox12.Items.Add(1400);
		 }
		
		 else if (comboBox42.Text == "Electric Toaster")
		 {
			 comboBox12.Items.Clear();
			 label67.Text = "1";
			 comboBox12.Items.Add(800);
			 comboBox12.Items.Add(1150);
			 comboBox12.Items.Add(1500);
		 }
		
		 else if (comboBox42.Text == "Microwave Oven")
		 {
			 comboBox12.Items.Clear();
			 label67.Text = "1";
			 comboBox12.Items.Add(900);
			 comboBox12.Items.Add(950);
			 comboBox12.Items.Add(1000);
		 }
		
		 else if (comboBox42.Text == "LED TV")
		 {
			 comboBox12.Items.Clear();
			 label67.Text = "1";
			 comboBox12.Items.Add(87);
			 comboBox12.Items.Add(106);
			 comboBox12.Items.Add(125);
		 }
		
		 else if (comboBox42.Text == "Washing Machine")
		 {
			 comboBox12.Items.Clear();
			 label67.Text = "1.9";
			 comboBox12.Items.Add(330);
			 comboBox12.Items.Add(423);
			 comboBox12.Items.Add(515);
		 }
		
		 else if (comboBox42.Text == "Vacuum Cleaner")
		 {
			 comboBox12.Items.Clear();
			 label67.Text = "1.7";
			 comboBox12.Items.Add(1200);
			 comboBox12.Items.Add(1600);
			 comboBox12.Items.Add(2000);
		 }
		
		 else if (comboBox42.Text == "Electric Iron")
		 {
			 comboBox12.Items.Clear();
			 label67.Text = "1";
			 comboBox12.Items.Add(1000);
			 comboBox12.Items.Add(1700);
			 comboBox12.Items.Add(2400);
		 }
		
		 else if (comboBox42.Text == "Laptop")
		 {
			 comboBox12.Items.Clear();
			 label67.Text = "1";
			 comboBox12.Items.Add(20);
			 comboBox12.Items.Add(48);
			 comboBox12.Items.Add(75);
		 }
		
		
	 }
	
	 private void comboBox41_SelectedIndexChanged(object sender, EventArgs e)
	 {
		 if (comboBox41.Text == "Fluorescent Light")
		 {
			 comboBox13.Items.Clear();
			 label68.Text = "1";
			 comboBox13.Items.Add(22);
			 comboBox13.Items.Add(32);
			 comboBox13.Items.Add(48);
		 }
		 else if (comboBox41.Text == "Fridge")
		 {
			 comboBox13.Items.Clear();
			 label68.Text = "2";
			 comboBox13.Items.Add(1000);
			 comboBox13.Items.Add(1700);
			 comboBox13.Items.Add(2400);
		 }
		 else if (comboBox41.Text == "Air Conditioner")
		 {
			 comboBox13.Items.Clear();
			 label68.Text = "4";
			 comboBox13.Items.Add(800);
			 comboBox13.Items.Add(1000);
			 comboBox13.Items.Add(1400);
		 }
		 else if (comboBox41.Text == "Electric Toaster")
		 {
			 comboBox13.Items.Clear();
			 label68.Text = "1";
			 comboBox13.Items.Add(800);
			 comboBox13.Items.Add(1150);
			 comboBox13.Items.Add(1500);
		 }
		 else if (comboBox41.Text == "Microwave Oven")
		 {
			 comboBox13.Items.Clear();
			 label68.Text = "1";
			 comboBox13.Items.Add(900);
			 comboBox13.Items.Add(950);
			 comboBox13.Items.Add(1000);
		 }
		 else if (comboBox41.Text == "LED TV")
		 {
			 comboBox13.Items.Clear();
			 label68.Text = "1";
			 comboBox13.Items.Add(87);
			 comboBox13.Items.Add(106);
			 comboBox13.Items.Add(125);
		 }
		 else if (comboBox41.Text == "Washing Machine")
		 {
			 comboBox13.Items.Clear();
			 label68.Text = "1.9";
			 comboBox13.Items.Add(330);
			 comboBox13.Items.Add(423);
			 comboBox13.Items.Add(515);
		 }
		 else if (comboBox41.Text == "Vacuum Cleaner")
		 {
			 comboBox13.Items.Clear();
			 label68.Text = "1.7";
			 comboBox13.Items.Add(1200);
			 comboBox13.Items.Add(1600);
			 comboBox13.Items.Add(2000);
		 }
		 else if (comboBox41.Text == "Electric Iron")
		 {
			 comboBox13.Items.Clear();
			 label68.Text = "1";
			 comboBox13.Items.Add(1000);
			 comboBox13.Items.Add(1700);
			 comboBox13.Items.Add(2400);
		 }
		 else if (comboBox41.Text == "Laptop")
		 {
			 comboBox13.Items.Clear();
			 label68.Text = "1";
			 comboBox13.Items.Add(20);
			 comboBox13.Items.Add(48);
			 comboBox13.Items.Add(75);
		 }
	 }

how to shorten the coding? how to use go to Function to retrieve info for each appliance?
  • 0

#2 Orjan

Orjan

    CC Mentor

  • Moderator
  • 2918 posts
  • Location:Karlstad, Sweden
  • Programming Language:C, Java, C++, C#, PHP, JavaScript, Pascal
  • Learning:Java, C#

Posted 05 July 2012 - 05:12 AM

you would as easiest make a data table or structure to handle the data. I would an class called Item which has the members that you add to the combobox, the text to the label and the id and the name of the item. store them in an arraylist and use as connected value to the name in the combobox41.
  • 0

I'm a System developer at XLENT Consultant Group mainly working with SugarCRM.
Please DO NOT send mail or PM to me with programming questions, post them in the appropriate forum instead, where I and others can answer you.


#3 Tonchi

Tonchi

    Helping the world with programming

  • Expert Member
  • PipPipPipPipPipPipPip
  • 1249 posts
  • Location:Zagreb
  • Programming Language:C#, Others
  • Learning:C, C++, Python, JavaScript, Transact-SQL, Assembly

Posted 05 July 2012 - 05:46 AM

please try to avoid goto function. Goto function is the jump function. I don't know why but everyone tries to avoid that function. Be more specific what do you want to short in your code. Your code is simple but I need to know what do you want to short.
  • 0

Microsoft Student Partner, Microsoft Certified Professional


#4 Orjan

Orjan

    CC Mentor

  • Moderator
  • 2918 posts
  • Location:Karlstad, Sweden
  • Programming Language:C, Java, C++, C#, PHP, JavaScript, Pascal
  • Learning:Java, C#

Posted 05 July 2012 - 07:54 AM

you avoid the goto function as it makes your code harder to read and understand. usually, it can make your code have many loose ends which is hard to manage (and therefore it's called spaghetti programming based on how a bunch of fresh boiled spaghetti looks like when you take it out of the pan), also, it can make knots on the code structure if you jump back and forth in an uncontrolled way, as the spaghetti can do if you whirl it while boiling
  • 0

I'm a System developer at XLENT Consultant Group mainly working with SugarCRM.
Please DO NOT send mail or PM to me with programming questions, post them in the appropriate forum instead, where I and others can answer you.






Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download