Desperate34
asked on
Variable is Int64 type but get error System.OverflowException
Hi
I'm trying to do:
Dim MyNumber As Integer
Dim Long_Number As Int64
MyNumber = 407,414
Long_Number = MyNumber * 1024 * 1024
' Result is : 437,690,302,464
But got this error:
System.OverflowException: Arithmetic operation resulted in an overflow.
It is not supposed that a long type number can store up to 9,223,372,036,854,775,807 ?
Also I try to do this:
Long_Number = CType(MyNumber * 1024 * 1024, Int64)
But got this error: Long_Number = 0
I'm trying to do:
Dim MyNumber As Integer
Dim Long_Number As Int64
MyNumber = 407,414
Long_Number = MyNumber * 1024 * 1024
' Result is : 437,690,302,464
But got this error:
System.OverflowException: Arithmetic operation resulted in an overflow.
It is not supposed that a long type number can store up to 9,223,372,036,854,775,807 ?
Also I try to do this:
Long_Number = CType(MyNumber * 1024 * 1024, Int64)
But got this error: Long_Number = 0
Try using Decimal.
Bob
Bob
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Long_Number = MyNumber * 1024 * 1024
calculation, try casting the MyNumber to Int64, otherwise I suspect the right side of this equation is by default cast to Integer. You have Integer * 1024 * 2024, which is cast to Integer, but is too big.