Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Arithmetic operation resulted in an overflow

Status
Not open for further replies.

randmeer

Technical User
Nov 1, 2005
7
NL
Hello,

I am trying to make a little program, but I face a problem as described below.
Value-1 and Value-2 are data type short, Answ is data type integer; big enough to contain the answer of the multiplication of value-1 and value-2. But still I got an error message after the multiplication. If I change value-2 into data type integer everything goes alright.


Why? Can anybody help me?


Dim value-1 As Short = 165
Dim value-2 As Short = 2400
Dim answ As integer

Answ = value-1 * value-2

Reports the following error:
Additional information: Arithmetic operation resulted in an overflow.
In the debugger:
Constant expression not represent able in type 'Short'.


Thanks in advance
 
It's actually normal because the compiler will first set aside a short to store it's result and then cast that to an integer.

Did you try them as integers or casting them to integers before doing the operation?

Christiaan Baes
Belgium

"My new site" - Me
 
Okay, I understand. Casting to integers works fine.

Thanks a lot.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top