Results 1 to 9 of 9

Thread: [RESOLVED] [2005] OverflowException was unhandled

  1. #1

    Thread Starter
    Banned
    Join Date
    Jul 2007
    Posts
    400

    Resolved [RESOLVED] [2005] OverflowException was unhandled

    Hi guys

    I have trouble with the code I have received. I do not understand with the sense at all, the code suppose to be correct and they suppose to be reading the size of the image on my hard disk but the error code shows it didn't make any sense



    Here it the code:

    Code:
            Dim D As New IO.DriveInfo("C")
            Dim Size As Integer = CInt(D.AvailableFreeSpace)
            Size /= 1073741824
            Label16.Text = CStr(Size) & "GB"


    Error I have received: Arithmetic operation resulted in an overflow.




    Any idea?




    Thanks,
    Mark
    Last edited by Mark103; Mar 26th, 2008 at 02:04 PM.

  2. #2
    Frenzied Member
    Join Date
    May 2006
    Location
    Toronto, ON
    Posts
    1,093

    Re: [2005] OverflowException was unhandled

    The integer datatype has a maximum value of 2,147,483,647. If you've got more free space than that, it'll throw this error.

    The AvailableFreeSpace property returns a Long datatype, which holds more and you should change your size variable to that.
    (VB/C#) is clearly superior to (C#/VB) because it (has/doesn't have) <insert trivial difference here>.

  3. #3

    Thread Starter
    Banned
    Join Date
    Jul 2007
    Posts
    400

    Re: [2005] OverflowException was unhandled

    Thanks for your response, I have full space available which I have 5,558,483,647. That suppose to be working correctly otherwise I get the same error.



    However, any situation to get this resolve??



    Thanks,
    Mark


    Quote Originally Posted by Tom Sawyer
    The integer datatype has a maximum value of 2,147,483,647. If you've got more free space than that, it'll throw this error.

    The AvailableFreeSpace property returns a Long datatype, which holds more and you should change your size variable to that.

  4. #4
    Frenzied Member
    Join Date
    May 2006
    Location
    Toronto, ON
    Posts
    1,093

    Re: [2005] OverflowException was unhandled

    What more do you need to get it resolved?

    You're trying to put a number into an integer that's larger than the largest number allowed in an integer. That can't be done. You need to use a long.
    (VB/C#) is clearly superior to (C#/VB) because it (has/doesn't have) <insert trivial difference here>.

  5. #5
    Fanatic Member Clanguage's Avatar
    Join Date
    Jan 2008
    Location
    North Carolina
    Posts
    659

    Re: [2005] OverflowException was unhandled

    If you were using Option Strict you would get the message
    Option Strict disallow the converrsion from Double to Integer.
    I wish MS had made this Option on by default.
    CLanguage;
    IF Post = HelpFull Then
    RateMe
    Else
    Say("Shut UP")
    End If
    DotNet rocks
    VB 6, VB.Net 2003, 2005, 2008, 2010, SQL 2005, WM 5.0,ahem ?OpenRoad?

  6. #6

    Thread Starter
    Banned
    Join Date
    Jul 2007
    Posts
    400

    Re: [2005] OverflowException was unhandled

    Well, that's the only small little things that I need to get resolve with. Can you post any other better code that it will works better than this one??




    Thanks,
    Mark



    Quote Originally Posted by Tom Sawyer
    What more do you need to get it resolved?

    You're trying to put a number into an integer that's larger than the largest number allowed in an integer. That can't be done. You need to use a long.

  7. #7
    Frenzied Member
    Join Date
    May 2006
    Location
    Toronto, ON
    Posts
    1,093

    Re: [2005] OverflowException was unhandled

    Quote Originally Posted by Mark103
    Well, that's the only small little things that I need to get resolve with. Can you post any other better code that it will works better than this one??
    Not really, it's a pretty basic operation that you can't make much simpler.

    I suppose you could put the math on one line like:

    Dim size as Long = D.AvailableFreeSpace / 1073741824

    That wouldn't really make it any better, though.
    (VB/C#) is clearly superior to (C#/VB) because it (has/doesn't have) <insert trivial difference here>.

  8. #8
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,106

    Re: [2005] OverflowException was unhandled

    Dim size as Long = CLong(D.AvailableFreeSpace / 10737418)
    My usual boring signature: Nothing

  9. #9

    Thread Starter
    Banned
    Join Date
    Jul 2007
    Posts
    400

    Re: [2005] OverflowException was unhandled

    Thank you very much, now I can see the problem are fixed!



    Thanks for your help. Please don't forget to rate me as you can



    Thanks,
    Mark

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