Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

goto statement 1

Status
Not open for further replies.

Saturn57

Programmer
Aug 30, 2007
275
CA
I would like a save button to go and run a calculation area of my code. When I try this it tells be to insert the label name I want to go to. My question is how do i set the label to the area of code i need to goto?
 
why in the world are you using goto statements in .net?

if you want a save button to run a calculation, just wire a click event to the button and have the button call the calculate member on whatever class implements it.


Jason Meckley
Programmer
Specialty Bakers, Inc.
 
My problem is understanding how to call a calculate member. My calculate member in under a button click code.
 
I take it you want to call code that is contained in another click event? Within your save button event just call...

Code:
Button1_Click(null, null);

Ryan
 
instead of calling the click event with null arguments, create a private member to do the actual calculation, or create another object which manages the calculation and call it's member.

here are good and bad examples
Code:
private ICalculator calculator = new Calculator();

public void button_click_one(object sender, eventargs e)
{
   textbox.text = calculator.add(1, 2);
}

public void button_click_two(object sender, eventargs e)
{
   textbox.text = calculator.add(2, 3);
}
reasons why this is good.
1. separation of concerns
2. principle of least surprise is in affect
3. encapsulation of logic. the calculator object is responsible for computations. the presentation layer is responsible for displaying the computation

Code:
public void button_click_one(object sender, eventargs e)
{
   textbox.text = 1+2;
}

public void button_click_two(object sender, eventargs e)
{
   button_click_one(null, null);
}

reasons why this is not good.
1. no separation of concerns. the presentation layer is doing the logic
2. principle of least surprise does not apply. what happens when I call button_click_one(null, null)?
3. encapsulation is broken. we need to understand button_click_one to understand what button_click_one(null, null) does.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Thanks Jason... I have a lot to learn from you I think.
 
Thanks Jason... I have a lot to learn from you I think.
your welcome, I have a lot to learn myself :)

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Jason,
Is this class ("Calculator") avialable in vb.net? I can't find any

Zameer Abdulla
 
no, it's your class that you would recreate to encapsulate the logic.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top