Results 1 to 2 of 2
  1. #1
    3 Star Lounger
    Join Date
    Feb 2001
    Posts
    369
    Thanks
    2
    Thanked 1 Time in 1 Post

    Odd calculation behaviour (2000sp3)

    I receive an overflow error on this statement
    bVar1=Abs(bVar2-bVar3)
    if bVar2-bVar3<0 (all vars are byte). If I declare either Var2 or Var3 as variant (or even integer) instead of byte, I don't receive this error, however.
    I assume it's something to do with the way intermediate variables are set up, that although nowhere in this statement does a byte variable have a negative number assigned to it, Access assumes all intermediates will also be bytes.

    Does this apply generally to all expressions? Do all intermediaries have to be within the limits of the datatype of the "biggest" datatype variable in that expression?

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Odd calculation behaviour (2000sp3)

    >> Do all intermediaries have to be within the limits of the datatype of the "biggest" datatype variable in that expression?

    Yes, that is correct.

    The values of the Byte data type range from 0 to 255. Since bVar2 and bVar3 are both bytes, bVar2 - bVar3 is evaluated as a byte too, resulting in an overflow error. To get around this, cast at least one of them as an integer or long integer, for example bVar2 - CLng(bVar3) or CLng(bVar2) - cLng(bVar3).

Posting Permissions

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