Link to home
Start Free TrialLog in
Avatar of Desperate34
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
Avatar of m_larson_33
m_larson_33

in your
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.

Avatar of Bob Learned
Try using Decimal.

Bob
ASKER CERTIFIED SOLUTION
Avatar of m_larson_33
m_larson_33

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial