I'm working with a bit of old VB6 code that goes thus...
Dim STATUS As Integer
STATUS = -1
If (Not STATUS) Then
' do something
Else
' do something else
End If
so I was, naturally, wondering which branch of this code is executed. So does anyone know what the numeric values of True and False are in VB6?
Boolean values and operationsConstant true is 1 and constant false is 0. It is considered good practice, though, to write true and false in your program for boolean values rather than 1 and 0.
A Boolean value represents a truth value; that is, TRUE or FALSE. A Boolean expression or predicate can result in a value of unknown, which is represented by the null value.
Use the Boolean Data Type (Visual Basic) to contain two-state values such as true/false, yes/no, or on/off. The default value of Boolean is False . Boolean values are not stored as numbers, and the stored values are not intended to be equivalent to numbers.
C does not have boolean data types, and normally uses integers for boolean testing. Zero is used to represent false, and One is used to represent true.
In VB 6, True
has a numeric value of -1. False
has a numeric value of 0.
The reason for this is because the Boolean
data type is stored as a 16-bit signed integer. Therefore,
-1 evaluates to 16 1s in binary (1111111111111111). False
is 16 0s (0000000000000000). This produces the relationship that has held throughout the evolution of BASIC: True = Not False
.
True is stored as -1 and false as 0. Any non-zero value is considered as true.
To see why it is so please check - http://www.vbforums.com/showthread.php?t=405047
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With