-
For loop Overflowing
well, i have this code:
For lngCounter = 0 To lngNumberResources - 1
Get #1, lngOffsetResources + 11 + (lngCounter * 14), ArrBytWOWTempArray1()
ArrDblResources(lngCounter) = ArrBytWOWTempArray1(0) * ArrBytWOWTempArray1(1)
ArrDblResourcesBIFF(lngCounter) = ArrBytWOWTempArray1(2) * ArrBytWOWTempArray1(3)
Next
lngNumberResources end up being = 16696
basically it reads a certain value and put it into a array of doubles to be read from later.
it overflows at lngCounter = 1042 (right after the Get)
any clue as to why?
-
Which line overflows? Have you put a breakpoint at that line to see what is in the variables?
-
well, the byte0*byte1 overflows.
128*2 respectively.
I replaced it with 256 with F8, and then replace the code back and it overflowed on the next loop
-
Byte values are only valid from 0-255....
-
so a byte * a byte cannot be greater than 255 even if the value is placed into a double?
-
I think that is correct, since the math is done, then assigned to the variable, so given the current amount of storage the two Bytes have, it would overflow.
:)
-
You'd have to convert them to doubles first, then multiply them...
-
You need to change from byte multiplication to something bigger.
eg
change
Code:
ArrDblResources(lngCounter) = ArrBytWOWTempArray1(0) * ArrBytWOWTempArray1(1)
to
Code:
ArrDblResources(lngCounter) = cLng(ArrBytWOWTempArray1(0)) * ArrBytWOWTempArray1(1)
-