ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   True and True (https://www.excelbanter.com/excel-programming/289779-true-true.html)

Tim Childs

True and True
 
Hi

pl can someone explain why the ansers are negative in the extract from the
Immediate box

thanks

Tim

?true + true

-2



? True + TRUE

-2



?true + false

-1




Frank Kabel

True and True
 
Hi Tim
in VBA TRUE evaluates to -1 (opposed to 1 in Excel formulas)
so in your case TRUE + TRUE = (-1) + (-1) = -2 and TRUE + FALSE = (-1)
+ 0 = -1

HTH
Frank

Tim Childs wrote:
Hi

pl can someone explain why the ansers are negative in the extract
from the Immediate box

thanks

Tim

?true + true

-2



? True + TRUE

-2



?true + false

-1




Leo Heuser[_2_]

True and True
 
Hi Tim

That's because contrary to TRUE in Excel,
which is 1, TRUE in VBA is -1

--
Best Regards
Leo Heuser

Followup to newsgroup only please.

"Tim Childs" skrev i en meddelelse
...
Hi

pl can someone explain why the ansers are negative in the extract from the
Immediate box

thanks

Tim

?true + true

-2



? True + TRUE

-2



?true + false

-1






Rob van Gelder[_4_]

True and True
 
Tim,

False is 0
True is actually better thought of as NOT 0.
In 8 bit binary:
00000000 = False
11111111 = True

If that binary number for True is represented as a signed byte, it turns out
to be -1


--
Rob van Gelder - http://www.vangelder.co.nz/excel


"Tim Childs" wrote in message
...
Hi

pl can someone explain why the ansers are negative in the extract from the
Immediate box

thanks

Tim

?true + true

-2



? True + TRUE

-2



?true + false

-1






Tim Childs

True and True
 
Frank

many thanks - it seems bizarre on the one hand but it certainly explains the
responses in the Immediate window

regards

Tim


"Frank Kabel" wrote in message
...
Hi Tim
in VBA TRUE evaluates to -1 (opposed to 1 in Excel formulas)
so in your case TRUE + TRUE = (-1) + (-1) = -2 and TRUE + FALSE = (-1)
+ 0 = -1

HTH
Frank






All times are GMT +1. The time now is 03:43 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com