Click to See Complete Forum and Search --> : Why does overflow!?


Hoagie
August 17th, 2001, 06:44 PM
This is bugging the hell out of me!

Does someone have any idea why this is chunk of code is overflowing on the 5th line!? If I remove the '1800' the overflow shifts to line 7.


iCellFrames = iCellFrames + iShiftFrames
iHours = Int(((iCellFrames / 60) / 60) / 30)
iCellFrames = iCellFrames - (108000 * iHours)
iMinutes = Int((iCellFrames / 60) / 30)
iCellFrames = iCellFrames - (1800 * iMinutes)
iSeconds = Int(iCellFrames / 30)
iCellFrames = iCellFrames - (30 * iSeconds)




I used several MsgBox inserts to check the values as it was stepping through and everything was right where it should be! I don't understand why I am getting overflow on such a horribly simple math problem!!

iCellFrames and iShiftFrames are 'Long'
iHours, iMinutes, iSeconds are 'Integer'

Many thanks for any help.

Hoag

John G Duffy
August 17th, 2001, 06:59 PM
What are the values of iCellFrames and IshiftFrames at entry to the routine?

I would put a

Debug.print iCellFrames - (1800 * iMinutes)



just before the failing instruction to see what is going on.
The computed value is out side the range of a Long.

John G

Hoagie
August 17th, 2001, 07:09 PM
but that shouldn't be possible... being outside the range of a Long.

iCellFrames is a Long and is perfectly fine up until that point. I am then taking that value and *subtracting* from it (and it does remain above 0). Unless VB requires a Long to be above a certain number (which would be just plain stupid), this statement should go out of any bounds.

Here are a list of variable values as the block exicutes for a given value...

line 1 (iCellFrames): 154888
line 2 (iHours): 1
line 3 (iCellFrames): 46888
line 4 (iMinutes): 26

John G Duffy
August 17th, 2001, 07:22 PM
If you give me the starting values requested, I will run the routine on my computer and check out the results.


John G

Hoagie
August 17th, 2001, 07:33 PM
you can set iShiftFrames to 108000 and iCellFrames to 46888 -- that will burn it. You can also set iShiftFrames to 1, and it will kill it as well.

John G Duffy
August 17th, 2001, 07:34 PM
'
(1800 * iMinutes) is producing your error.
Change iMinutes to a long and your problem will go away.
1800 * 26 = 46800 which exceeds the range of an Integer

John G

Hoagie
August 17th, 2001, 07:44 PM
Sure enough, many thanks for the pointer!

Although I'm ont clear as to why VB is trying to put (1800 * iMinutes) into an Integer value, and not just doing the math. But it works now, and I know another quirk of VB... so thanks again! :)

Nick

d.paulson
August 17th, 2001, 08:31 PM
Well 1800 will fit into an integer. An integer * integer results in an integer value also. This is why the overflow error. A long * integer results in a long. So in order to calculate this equation, either the 1800 must be declared as a long or iMinutes must be declared as a long. Since iMinutes has already be declared as an integer, the proper correction would be to type 1800 as a long. To do this you just add the type declaration character. & denotes a long, so you would put (1800& * iMinutes).

David Paulson