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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T10:11:54+00:00 2026-06-09T10:11:54+00:00

On entering negative values to a textbox I get an error saying Unhandled Exception:

  • 0

On entering negative values to a textbox I get an error saying Unhandled Exception: System.OverflowException: Value was either too large or too small for a UInt32.

Here is my code :

 UInt32 n = Convert.ToUInt32(textBox2.Text);    
         if (n > 0)
          //code 
         else
         //code
  • 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-06-09T10:11:56+00:00Added an answer on June 9, 2026 at 10:11 am

    That happens because UInt32 is unsigned. You should use Int32 (which is unsigned) instead.

    So your code should look like:

    Int32 n = Convert.ToInt32(textBox2.Text);
    if (n > 0)
      //code 
    else
      //code
    

    However, I would rather put it like that:

    int n;
    // TryParse method tries parsing and returns true on successful parsing
    if (int.TryParse(textBox2.Text, out n))
    {
        if (n > 0)
             // code for positive n
        else
             // code for negative n
    }
    else
         // handle parsing error
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

User Entering the Time Value in the Masked Textbox For Example User Enter Time
What is the best way to prevent users from entering negative values in an
When entering a code line in Aptana Studio like <input id=send type=button value=Send onclick=calculate()
If entering a label when a value is specified is redundant do you have
When users are entering information on my site and experience an exception, what is
If am entering some values in text box it should be simultaneously displayed in
Entering a value such as 27.8675309 into the Decimal representation field of the IEEE
How to stop entering value in UITextField if the length is greater then 20
based on the solution here: Entering values into database from 'unlimited' dynamic controls i
When entering an invalid email in Mail's NSTokenField one get's this (a mix of

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.