Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7653525
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T12:03:19+00:00 2026-05-31T12:03:19+00:00

I am currently building my project using windows forms and came across a minor

  • 0

I am currently building my project using windows forms and came across a minor “problem”.

I have the user enter an hour which is stored as an int. I want to provide detailed feedback to the user so that they know exactly what they have done wrong should they cause an error.

If no value is given, a format exception is thrown.
If anything but an integer is given, a format exception is thrown.

This means I cannot directly tell the user that the new item could not be added due to EITHER 1) no value or 2) not an integer as they both use the same exception.

How can I solve this and what would be the best solution?

Many thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T12:03:20+00:00Added an answer on May 31, 2026 at 12:03 pm

    some example code related to your question; note ValidateData in particular:

    // called from ok button click or similar event
    private void Accept()
    {
       if (!ValidateData())
          return;
    
       SaveData();
       DialogResult = DialogResult.Ok;
       Dispose();
    }
    
    private bool ValidateData()
    {
       int val;
    
       if (string.IsNullOrEmpty(mTextBox.Text))
          return FailValidation("Value can not be empty.", mTextBox);
    
       if (!int.TryParse(mTextBox.Text, out val))
           return FailValidation("Value was not an integer.", mTextBox);
    
       return true;
    }
    
    // do something with the value if you need
    private void SaveData()
    {       
    }
    
    // post a message to the user, and highlight the problematic control
    // always evaluates to false
    private bool FailValidation(string pMessage, Control pControl)
    {
         if (pControl != null)
         {
            pControl.Focus();
            TextBox textBox = pControl as TextBox;
            if (textBox != null)
               textBox.SelectAll();
         }
    
         AlertBox(pMessage);
         return false;
    }
    
    // quick alert message method
    private void AlertBox(string pMessage)
    {
       return MessageBox.Show
       (
          pMessage,          
          Application.ProductName,
          MessageBoxButtons.OK,
          MessageBoxIcon.Exclamation,
          MessageBoxDefaultButton.Button1
       );
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently using ANT for building my Java project on a Windows XP machine.
I'm currently using ant for building my java project on a Windows XP machine.
I have been using raphael.draggable with a project that I am currently building. I
I'm currently building a semi-small ruby app for a project. The problem I'm currently
I'm working on a CakePHP project and am currently building the user authentication part
I'm currently using Fusioncharts Free in my project which requires XML to be in
I have a MonoTouch project using some code I share with a Windows Phone
I have a project that is currently in production delivering some web-services using the
I currently have a project I am building in Visual Studio 2005 and I
I'm currently building a project and I would like to make use of some

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.