CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Apr 2010
    Posts
    1

    Creating a method for error messageboxes

    I am building a pretty in depth wage calculator for class and I have to display a message box whenever a user's cumulative input for one days hours exceeds 24. In this phase of the project the professor wants me to encapsulate these error messages into a method to be called from the locations where I originally had these messages coded. I'm not sure how to proceed here. An example of my message is as follows:

    if (dblTotalMon > 24)
    {
    MessageBox.Show (
    "There are only 24 hours in a day! Please re-enter your hours.",
    "Input Error", MessageBoxButtons.Ok,
    MessageBoxIcon.Exclamation);
    }

    I have a lot of these messages and need to put them in a method within my form.

    Any suggestions are welcome!

  2. #2
    Join Date
    Jun 2008
    Posts
    2,477

    Re: Creating a method for error messageboxes

    Ok... so, you have to essentially write a wrapper for the existing method MessageBox.Show( )?

    Code:
    void ShowError( string errMsg, string caption )
    {
        MessageBox.Show( errMsg, caption, MessageBoxButtons.OK, MessageBoxIcon.Error );
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured