Mystery Overflow Problem (1 Viewer)

mr_fish

Registered User.
Local time
Today, 03:40
Joined
Dec 8, 2005
Messages
40
Hi everybody,

Getting an overflow error that i just can't fathom.

Basically the code takes a string field tbl_Media_Page_Size (e.g. 297 x 210) and strips the left and right numbers into num1 and num2 then tries to multiply them. It always overflows whether I'm using integer, long, single or double and I'm not sure why.

A watch confirms the figures in num1 and num2 are 297 and 210, I can add, divide or minus the number and it works, but it always overflows on a multiplication.

Dim stReadPageSize As String
Dim iPageSize As Long
Dim StringLength As Integer
Dim iPos As Integer
Dim num1 As Integer
Dim num2 As Integer

stReadPageSize = Trim(tbl_Media_Page_Size)
StringLength = Len(stReadPageSize)
iPos = InStr(1, stReadPageSize, "x")
StringLength = (StringLength - iPos)
iPos = iPos - 1
num1 = CInt(Left(stReadPageSize, iPos))
num2 = CInt(Right(stReadPageSize, StringLength))

iPageSize = num1 * num2
MsgBox iPageSize

Any help with this annoying problem is most appreciated.

Thanks,

Jon
 

john471

Registered User.
Local time
Today, 12:40
Joined
Sep 10, 2004
Messages
392
297 * 210 = 62370

An integer can only store numbers in the range -32,768 to 32,767.

Whilst you are trying to assign the end result to a Long Integer, I think the type of the operands (variables Num1 & Num2, in your case) comes into play first. Dimension (declare) the Num1 and Num2 both as Long Integer, and your problem should go away (at least until you exceed the bounds of a Long Integer).

HTH Regards

John
 

KenHigg

Registered User
Local time
Yesterday, 22:40
Joined
Jun 9, 2004
Messages
13,327
Dim num1 and num2 as long

???
 

KenHigg

Registered User
Local time
Yesterday, 22:40
Joined
Jun 9, 2004
Messages
13,327
Looks like we posted at the same time (almost :) )

(You're either up early or late?)
 

john471

Registered User.
Local time
Today, 12:40
Joined
Sep 10, 2004
Messages
392
I realised we posted at the same time - that's why the "cheeky grin" is there.

It is only 21:20 now, and 20:34 when I posted initial reply, so not really that late. Of course we're closing off Wednesday, and you're just opening it....

Edit : -
Oh, OK , it is now called a "big grin", I thought it was a "cheeky grin"... :D
 

mr_fish

Registered User.
Local time
Today, 03:40
Joined
Dec 8, 2005
Messages
40
Thanks guys, didn't realise all variable data types in an equation had to be able to handle the size of the result.
 

Users who are viewing this thread

Top Bottom