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 6235381
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T10:39:35+00:00 2026-05-24T10:39:35+00:00

Using VS2010 Express, C# and it’s WinForms Application. Here I have three text boxes(aTextBox,

  • 0

Using VS2010 Express, C# and it’s WinForms Application.

Here I have three text boxes(aTextBox, bTextBox, cTextBox) from which Inputs are strings and then using int.Parse(aTextBox.Text) converted to integers.

Then a Button (calcBtn) method which is going to calculate charges and then to display results after some maths to particular TextBoxes on Result groupBox which again contains text boxes for results…

The problem is causing by the way I am parsing or the order in which it’s executing. If any of the textbox is filled then result should display and not to get in the format exceptions. Here I am getting stuck because inside the calcBtn I am parsing all text boxes and if one of them is empty then exception occurs. Compiler is I guess trying to parse empty strings from the empty text boxes, and I don’t want it to be.

Any suggestions if you got what I mean? 🙂

Here’s what GUI looks like
enter image description here

  • 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-24T10:39:36+00:00Added an answer on May 24, 2026 at 10:39 am

    The Int32.Parse method does not accept malformed strings, and this includes empty strings. I have two suggestions.

    You could check if the string is empty/whitespace first, and return 0 or some other default value:

    private static int ParseInteger(string str)
    {
        if (str == null || str.Trim() == "")
            return 0;
    
        // On .NET 4 you could use this instead.  Prior .NET versions do not
        // have the IsNullOrWhiteSpace method.
        //
        // if (String.IsNullOrWhiteSpace(str))
        //    return 0;
    
        return Int32.Parse(str);
    }
    

    Or you could simply ignore all parsing errors, treating them as 0. This will treat things like "", "123abc", and "foobar" as zero.

    private static int ParseInteger(string str)
    {
        int value;
        if (Int32.TryParse(str, out value))
            return value;
    
        return 0;
    }
    

    Which approach you take depends on the specific needs of your application.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been using VS2010 without any issues, always on the same application. Suddenly
Using VS2010 and SQL express 2005, Ive created a database, created a simple table,
how can I enable database logging in my ASP.net application? I am using VS2010
I have a VERY simple C# Winforms project that I made using Visual Studio
Right now I am writing a little c++ console program using VS2010 Express. The
I'm using VS2010 express to create a game built with xna . I'm trying
I have a solution in C:\full path here\VS2010\blender.sln This solution contains many projects(around 100).
Using online interfaces to a version control system is a nice way to have
Using TortoiseSVN against VisualSVN I delete a source file that I should not have
Using VS2008, C#, .Net 2 and Winforms how can I make a regular Button

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.