Results 1 to 4 of 4

Thread: What is a Boolean?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 1999
    Location
    Glasgow,Scotland
    Posts
    281

    Hi,

    My VB 6 help isn't working so I couldn't find an answer - says I have to install MSDN library or something. I also tried a search on this board but couldn't find a simple answer.

    So what's a boolean? It's something I've been cutting and pasting throughout my project, but I'd like to know how it works and what it is.

    Thanks for any help!

  2. #2
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    A boolean variable can only have two values:
    0 - False
    -1 - True
    when you convert to boolean with cbool or assinging a nonbolean value to a boolean value everything except 0 is True. To declare a boolean variable:
    Code:
    Dim a as boolean
    private a as boolean
    public a as boolean
    also a boolean variables takes up 2 bytes
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  3. #3
    Fanatic Member
    Join Date
    Feb 2000
    Location
    Japan
    Posts
    840
    be a bit careful, VB is a little erratic, sometimes -1 is false, as is the case where -1 is returned from some search funtions when nothing is found (like rtfbox.find() ) although not the instr() which is fine.

    Where possible refer to just True & False

    Binary is:
    1 = true
    0 = False

    but the boolean data type is 16 bit which makes things a little odd.

    I find that it's best benefit is that it makes code more readable saying that something is true or false rather than have a value.



    Paul Dwyer
    Network Engineer
    Aussie In Tokyo

    Using Powerbasic 6 & VB6 SP4 (Please also add your VB Version to your signature!)

  4. #4
    Hyperactive Member
    Join Date
    Jan 1999
    Location
    Rotterdam, Netherlands
    Posts
    386
    If a function returns -1 to indicate nothing was found, it's declared as integer or long, not as boolean.
    A boolean is within VB always 0 and -1, although it accepts 0 as false and anything else as true. (and luckily, every other programming language I know 0 = false and 1 = true...).
    But I agree, if you use the find function in a If Then statement, you need to be careful indeed (but then still, it's not a boolean that is returned and therefor it's recommended to check for " = -1" or " > -1".....
    Hope this helps

    Crazy D

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