Click here to Skip to main content
15,905,782 members
Home / Discussions / C#
   

C#

 
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


AnswerRe: Argument [modified] Pin
DaveyM6927-Apr-09 23:13
professionalDaveyM6927-Apr-09 23:13 
QuestionSomething with a delegate Pin
Joramq27-Apr-09 21:51
Joramq27-Apr-09 21:51 
AnswerRe: Something with a delegate Pin
Christian Graus27-Apr-09 22:07
protectorChristian Graus27-Apr-09 22:07 
GeneralRe: Something with a delegate Pin
Joramq27-Apr-09 22:10
Joramq27-Apr-09 22:10 
AnswerRe: Something with a delegate Pin
OriginalGriff27-Apr-09 22:10
mveOriginalGriff27-Apr-09 22:10 
AnswerRe: Something with a delegate Pin
N a v a n e e t h27-Apr-09 22:38
N a v a n e e t h27-Apr-09 22:38 
GeneralRe: Something with a delegate Pin
Joramq27-Apr-09 23:09
Joramq27-Apr-09 23:09 
GeneralRe: Something with a delegate Pin
N a v a n e e t h28-Apr-09 0:09
N a v a n e e t h28-Apr-09 0:09 
GeneralRe: Something with a delegate Pin
Joramq28-Apr-09 0:17
Joramq28-Apr-09 0:17 
GeneralRe: Something with a delegate Pin
Tom Deketelaere28-Apr-09 1:20
professionalTom Deketelaere28-Apr-09 1:20 
GeneralRe: Something with a delegate Pin
N a v a n e e t h28-Apr-09 1:59
N a v a n e e t h28-Apr-09 1:59 
AnswerRe: Something with a delegate Pin
Luc Pattyn28-Apr-09 1:17
sitebuilderLuc Pattyn28-Apr-09 1:17 
GeneralRe: Something with a delegate Pin
Joramq28-Apr-09 2:03
Joramq28-Apr-09 2:03 
Questionhow can i send mail to all the members at a once...database contains the user details and email addresses........ Pin
jiya131127-Apr-09 21:10
jiya131127-Apr-09 21:10 
AnswerRe: how can i send mail to all the members at a once...database contains the user details and email addresses........ Pin
dotnetmember27-Apr-09 21:26
dotnetmember27-Apr-09 21:26 
QuestionImage to bitmap conversion error...again! Pin
sebogawa27-Apr-09 21:02
sebogawa27-Apr-09 21:02 
AnswerRe: Image to bitmap conversion error...again! Pin
stancrm27-Apr-09 21:24
stancrm27-Apr-09 21:24 

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.