Click here to Skip to main content
15,922,584 members
Home / Discussions / C#
   

C#

 
AnswerRe: Argument Pin
musefan27-Apr-09 22:06
musefan27-Apr-09 22:06 
GeneralRe: Argument Pin
CPallini27-Apr-09 22:09
mveCPallini27-Apr-09 22:09 
GeneralRe: Argument Pin
musefan27-Apr-09 23:01
musefan27-Apr-09 23:01 
GeneralRe: Argument Pin
CPallini27-Apr-09 23:04
mveCPallini27-Apr-09 23:04 
GeneralRe: Argument Pin
musefan27-Apr-09 23:46
musefan27-Apr-09 23:46 
GeneralRe: Argument Pin
CPallini27-Apr-09 23:52
mveCPallini27-Apr-09 23:52 
GeneralRe: Argument Pin
musefan28-Apr-09 0:02
musefan28-Apr-09 0:02 
GeneralRe: Argument Pin
CPallini28-Apr-09 0:16
mveCPallini28-Apr-09 0:16 
GeneralRe: Argument Pin
musefan28-Apr-09 0:30
musefan28-Apr-09 0:30 
GeneralRe: Argument Pin
Henry Minute28-Apr-09 0:38
Henry Minute28-Apr-09 0:38 
GeneralRe: Argument Pin
musefan28-Apr-09 0:50
musefan28-Apr-09 0:50 
GeneralRe: Argument Pin
Henry Minute28-Apr-09 0:58
Henry Minute28-Apr-09 0:58 
GeneralRe: Argument Pin
CPallini28-Apr-09 1:41
mveCPallini28-Apr-09 1:41 
GeneralRe: Argument Pin
musefan28-Apr-09 1:53
musefan28-Apr-09 1:53 
GeneralRe: Argument Pin
CPallini28-Apr-09 1:56
mveCPallini28-Apr-09 1:56 
GeneralRe: Argument Pin
musefan28-Apr-09 2:06
musefan28-Apr-09 2:06 
GeneralRe: Argument Pin
BabyOreo27-Apr-09 23:05
BabyOreo27-Apr-09 23:05 
GeneralRe: Argument Pin
musefan27-Apr-09 23:47
musefan27-Apr-09 23:47 
GeneralRe: Argument Pin
BabyOreo27-Apr-09 23:52
BabyOreo27-Apr-09 23:52 
GeneralRe: Argument Pin
musefan28-Apr-09 0:45
musefan28-Apr-09 0:45 
AnswerRe: Argument Pin
SeMartens27-Apr-09 22:08
SeMartens27-Apr-09 22:08 
AnswerRe: Argument Pin
N a v a n e e t h27-Apr-09 22:35
N a v a n e e t h27-Apr-09 22:35 
AnswerRe: Argument Pin
12Code27-Apr-09 23:07
12Code27-Apr-09 23:07 
GeneralRe: Argument Pin
BabyOreo27-Apr-09 23:13
BabyOreo27-Apr-09 23:13 
GeneralRe: Argument Pin
Luc Pattyn28-Apr-09 1:10
sitebuilderLuc Pattyn28-Apr-09 1:10 
Hi,

split your code into two methods:
1. one contains the "bunsiness logic" and no GUI stuff (No MessageBox); it does not take sender or eventargs as parameters, and it does return a calculated value and outputs (through out parameter) a string which should be shown to the user.
2. the buttonClickHandler which mainly calls the other method and shows the MessageBox when there is a need to.

private void btnAddEntry_Click(object sender, EventArgs e) {
    string s;
    double result=calculate(out s);
    if (s==null) textBox.Text="The result is "+result;
    else MessageBox.Show(s);
}

private double calculate(out string message) {
    message=null;
    double result=...;
    if (...) message="Something went wrong";
    ...
    return result;
}


That way you can easily perform unit tests on the business logic, and there probably won't be a need to test the actual buttonClickHandler anymore.

Smile | :)

Luc Pattyn [Forum Guidelines] [My Articles]

Avoiding unwanted divs (as in "articles needing approval") with the help of this FireFox add-in


General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.