Reputation: 23285
I was helping with another question, and I realized that using Evaluate
in VBA seems to return -1
for TRUE
statements.
Data:
Column A Column B
A A
A B
C C
So if I put =INT(A2=B2)
and drag down, I get 1, 0, 1
which I expect.
However, using the following VBA, I get -1, 0, -1
.
For i = 2 To 4
Cells(i, 4).Value = Evaluate(Int(Cells(i, 1) = Cells(i, 2)))
Next i
Why would EVALUATE
use -1
for TRUE
?
Upvotes: 3
Views: 99
Reputation: 234875
VBA uses -1 for the True value. Cf. C and C++ which use 1.
-1 has all bits set to 1 in a 2’s complement signed integral type so the choice has some sense.
The choice goes way back to DOS BASIC (and other BASICs such as the one on the old BBC Micro) which predates the Component Object Model of the mid 1990s that’s still in use today.
Upvotes: 8