|
-
Mar 26th, 2008, 01:08 PM
#1
Thread Starter
Banned
[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.
-
Mar 26th, 2008, 01:33 PM
#2
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>.
-
Mar 26th, 2008, 01:44 PM
#3
Thread Starter
Banned
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
 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.
-
Mar 26th, 2008, 01:49 PM
#4
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>.
-
Mar 26th, 2008, 01:52 PM
#5
Fanatic Member
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?
-
Mar 26th, 2008, 01:53 PM
#6
Thread Starter
Banned
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
 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.
-
Mar 26th, 2008, 01:57 PM
#7
Re: [2005] OverflowException was unhandled
 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>.
-
Mar 26th, 2008, 02:01 PM
#8
Re: [2005] OverflowException was unhandled
Dim size as Long = CLong(D.AvailableFreeSpace / 10737418)
My usual boring signature: Nothing
 
-
Mar 26th, 2008, 02:02 PM
#9
Thread Starter
Banned
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|