Help with simple arithmetic

  • Thread starter Thread starter ngohwoonhiong
  • Start date Start date
N

ngohwoonhiong

i have the following declaration and piece of code

Dim netProfit As Long
netProfit = (7364 - 2298) * 20


Why does it fail with "runtime error 6" Overflow.

the result should be 101320, should be okay for Long right ?

Any help appreciated.

Thanx
 
The right hand side involves only integers, so it evaluates as an
integer expression (which overflows). The final result (if it hadn't
overflowed) would then be coerced to long.

To perform the multiplication as a long instead of an integer, at least
one of the numbers must be a long, as in
netProfit = (7364 - 2298) * 20&

Jerry
 
Back
Top