• Byte vs Boolean (Access 2000)

    Author
    Topic
    #376179

    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?

    Viewing 1 reply thread
    Author
    Replies
    • #615151

      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?)

    • #615165

      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.

      • #615191

        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.

        • #615425

          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. grin 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.

    Viewing 1 reply thread
    Reply To: Byte vs Boolean (Access 2000)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: