VB.NET App: Validate Integer Range

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • karthickbabu
    New Member
    • Sep 2007
    • 33

    VB.NET App: Validate Integer Range

    Hi

    I done a Factorial Program in VB.NET. It works properly. If i give above than 12 factorial, it shows arithmetic exception. How can i check the Integer Range in VB.NET. I search in Web, finally i got Range Validator Control. But I am not having this control in my system, i am using VB.NET 2005 version. I am using conversion type also using Option Strict Statement.

    But not working till. kindly any suggestion



    Hope your Reply
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    Originally posted by karthickbabu
    Hi

    I done a Factorial Program in VB.NET. It works properly. If i give above than 12 factorial, it shows arithmetic exception. How can i check the Integer Range in VB.NET. I search in Web, finally i got Range Validator Control. But I am not having this control in my system, i am using VB.NET 2005 version. I am using conversion type also using Option Strict Statement.

    But not working till. kindly any suggestion



    Hope your Reply
    What exactly is your exception error message?
    Integer Data Type has a limited size range....howeve r 12! should fit into this range.

    Are you sure your factorial program is working properly?

    Comment

    • karthickbabu
      New Member
      • Sep 2007
      • 33

      #3
      Originally posted by Frinavale
      What exactly is your exception error message?
      Integer Data Type has a limited size range....howeve r 12! should fit into this range.
      Are you sure your factorial program is working properly?
      I get this error message "Arithmetic Operattion Resulted in an Overflow"
      My Factorial Program is Working from 1 to 12 but if i gives from 13 then only shows exception error message.

      Comment

      • Frinavale
        Recognized Expert Expert
        • Oct 2006
        • 9749

        #4
        Originally posted by karthickbabu
        I get this error message "Arithmetic Operattion Resulted in an Overflow"
        My Factorial Program is Working from 1 to 12 but if i gives from 13 then only shows exception error message.
        Did you read the link I posted previously?

        Every variable has to store its value into memory slot. Each variable type is given a specific amount of space to store this value.

        Because of this, the maximum number that you can store in an integer is
        2,147,483,647

        13! results in 6,227,020,800.

        This means that the number is too big to store in the memory that you have allocated for your result. This is why you are getting an overflow message...the value simply doesn't fit into the space you've given it (like pouring too much water into a cup)

        Consider using a Long data type instead of Integer.

        Comment

        • karthickbabu
          New Member
          • Sep 2007
          • 33

          #5
          Yes i read that link what u post at last. Then i change the integer data type to long data type.

          Thanks for your reply


          Originally posted by Frinavale
          Did you read the link I posted previously?

          Every variable has to store its value into memory slot. Each variable type is given a specific amount of space to store this value.

          Because of this, the maximum number that you can store in an integer is
          2,147,483,647

          13! results in 6,227,020,800.

          This means that the number is too big to store in the memory that you have allocated for your result. This is why you are getting an overflow message...the value simply doesn't fit into the space you've given it (like pouring too much water into a cup)

          Consider using a Long data type instead of Integer.

          Comment

          • Frinavale
            Recognized Expert Expert
            • Oct 2006
            • 9749

            #6
            Originally posted by karthickbabu
            Yes i read that link what u post at last. Then i change the integer data type to long data type.

            Thanks for your reply
            Are you still having problems?
            Or did the change to the Long data type fix the problem?

            Comment

            • karthickbabu
              New Member
              • Sep 2007
              • 33

              #7
              No now its working properly upto long range type

              Comment

              Working...