-
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!
-
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
-
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.
-
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".....