Results 1 to 9 of 9

Thread: For loop Overflowing

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2002
    Posts
    14

    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?

  2. #2

  3. #3

    Thread Starter
    New Member
    Join Date
    Jul 2002
    Posts
    14
    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

  4. #4
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    Byte values are only valid from 0-255....

  5. #5

    Thread Starter
    New Member
    Join Date
    Jul 2002
    Posts
    14
    so a byte * a byte cannot be greater than 255 even if the value is placed into a double?

  6. #6
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    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.

    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  7. #7
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    You'd have to convert them to doubles first, then multiply them...

    VB Code:
    1. Cdbl(byte0)*Cdbl(byte1)
    Last edited by nemaroller; Nov 6th, 2002 at 09:55 PM.

  8. #8
    Hyperactive Member
    Join Date
    Jun 2000
    Posts
    299
    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)

  9. #9

    Thread Starter
    New Member
    Join Date
    Jul 2002
    Posts
    14
    cooly cool

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width