Results 1 to 5 of 5
  1. #1
    2 Star Lounger
    Join Date
    Apr 2001
    Location
    Wellington, New Zealand
    Posts
    173
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Byte vs Boolean (Access 2000)

    I have just come across something interesting that I never realised, and thought that someone here may be able to spread light on it.

    In the MS Access VBA help documentation, the Data Type Summary pages, states that a byte uses 1 byte of storage space (which makes sense), but a Boolean uses 2 bytes.

    Now, with me, this just doesn't seem to fit!!! A boolean is really a bit isn't it? So why on earth would simple on, off (binary) data need to be stored as 2 bytes?

    Anyone?

  2. #2
    Super Moderator
    Join Date
    Jun 2002
    Location
    Mt Macedon, Victoria, Australia
    Posts
    3,993
    Thanks
    1
    Thanked 45 Times in 44 Posts

    Re: Byte vs Boolean (Access 2000)

    I have just looked in this up in several books.

    3 say that a boolean takes 2 bytes, and one says it takes one bit!

    They all agree that what is stored is -1 for yes and 0 for No. These are integers, so require 2 bytes.
    (Is that a reasonable explanation?)
    Regards
    John



  3. #3
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Byte vs Boolean (Access 2000)

    I believe it is because Access uses a signed value (0 or -1) as a boolean but will interpret any non-zero value as true. Byte datatypes are limited to unsigned values between 0 and 256.
    Charlotte

  4. #4
    Gold Lounger
    Join Date
    Jun 2001
    Location
    Crystal Beach, FL, Florida, USA
    Posts
    3,436
    Thanks
    1
    Thanked 34 Times in 34 Posts

    Re: Byte vs Boolean (Access 2000)

    You wrote:
    >>I believe it is because Access uses a signed value (0 or -1) as a boolean but will interpret any non-zero value as true. <<

    Charlotte,

    I think you have to be real careful with this. For example, in de###### if you enter "? 1 = True", the response is False. However, "?CBool(1) = True" is True.
    Mark Liquorman
    See my website for Tips & Downloads and for my Liquorman Utilities.

  5. #5
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Byte vs Boolean (Access 2000)

    I didn't say I used it like that, Mark. 1=True should always fail in Access because True is a constant with a value of -1. However, as you demonstrated, the CBool function evaluates the value 1 and determines that it isn't zero so it must be True. <img src=/S/grin.gif border=0 alt=grin width=15 height=15> Another way to do it is like this:

    If (intNonZero) Then ...

    where intNonZero represents an integer variable. The parens will force an evaluation of it as a true or false expression.
    Charlotte

Posting Permissions

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