Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the Integer values of Boolean False and True in VB6?

Tags:

vb6

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?

like image 997
Brian Hooper Avatar asked Nov 25 '10 10:11

Brian Hooper


People also ask

What is the integer value for Boolean true?

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.

What is true value in Boolean?

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.

What is Boolean in Visual Basic?

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.

Is 1 True or false C?

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.


2 Answers

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.

like image 168
Cody Gray Avatar answered Jan 19 '23 22:01

Cody Gray


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

like image 22
Unmesh Kondolikar Avatar answered Jan 19 '23 22:01

Unmesh Kondolikar