If you've used other programming languages you're probably used to TRUE being equal to 1 and FALSE equal to zero. In VB True is in fact equal to -1.
To understand this let's look at some basic boolean logic, specifically the NOT operator. As you should be well aware all digits (bits) in binary are 1 or 0. NOT is very simple, it inverses the number so that all 0's become 1's and vice versa.
Next let's look at how True and False are defined. False is simple - it is simply equal to zero. True, on the other hand, is defined as NOT False - so its value depends on how that is calculated. If we examine how numbers in VB are constructed we see that VB has no unsigned integers; they are all signed. A signed integer reserves the highest-order bit as the sign bit. In a 32 bit number if the sign bit is set to 0, the number is positive and its value is equal to the other 31 bits. If this bit is set to 1, the number is negative and its value equal to NOT of the other 31 bits.
Since False is zero and thus 32 "off" bits, NOT False comes to 32 "on" bits, including the sign bit. This negates the rest of the number and leaves us with the result, -1, which is the value of the TRUE constant.
As a side note, any non-zero value will be converted to True when cast to a Boolean type.


Reply With Quote

