# Var3 = (Var1 / Var 2) Arithmetic operation resulted in an overflow [Answered]RSS

## 2 replies

Last post May 04, 2008 07:04 PM by sabrick

Member

16 Points

119 Posts

### Var3 = (Var1 / Var 2) Arithmetic operation resulted in an overflow

I have the follow in my page:

Dim ImageWidth As Integer

Dim ImageHeigth As Integer

Dim ImageRatio As Integer

DBConn.Open()

':::::::::::::::::::::::::::::::::::::::::Row 1:::::::::::::::::::::::::::::::::::::::::::::::::::::::

DBCmd = New Data.SqlClient.SqlCommand("SELECT * FROM (SELECT *, ROW_NUMBER() OVER(ORDER BY [Date] DESC) AS rn FROM images) t WHERE rn=1", DBConn)

' Image resizer: Takes the Heigth x Width ratio, changes width to 150, changes heigth to the ratio of what 150 would make it

ImageWidth = Me.Image1.Width.Value ' This value = 842ImageHeigth = Me.Image1.Height.Value ' This value = 1000

ImageRatio = (ImageHeigth / ImageWidth) ' This is what gives me the error

It highlights " ImageRatio = (ImageHeigth / ImageWidth) " and says "Overflow exception was unhandled by user code: Arithmetic operation resulted in an overflow

what could be the problem? I subsitute the the varibles with actual numbers and it works fine

All-Star

16090 Points

3549 Posts

### Re: Var3 = (Var1 / Var 2) Arithmetic operation resulted in an overflow

I believe the result of the division will be of type float, so in order to store it in an int you will have to convert it.

ImageRatio = (int)(ImageHeight / ImageWidth)

And also you could try ImageRatio = Math.Round(ImageHeight / ImageWidth)

If this post was useful to you, please mark it as answer. Thank you!

Member

16 Points

119 Posts