AND Boolean
AND Boolean
(OP)
I'm trying to understand what AND is doing with the integers in the following code. Both a1 and b1 evaluate to TRUE but c1 evaluates to FALSE. Something similar to this code was in a spreadsheet made by someone else.
Any ideas on why some integers return c1=TRUE and others return c1=FALSE??
Sub testand()
Dim a1 As Integer
Dim b1 As Integer
Dim c1 As Boolean
a1 = 12
b1 = 2
c1 = (a1 And b1)
Sheet1.Range("E2").Value = c1
Sheet1.Range("E3").Value = CBool(a1)
Sheet1.Range("e4").Value = CBool(b1)
End Sub
Any ideas on why some integers return c1=TRUE and others return c1=FALSE??
Sub testand()
Dim a1 As Integer
Dim b1 As Integer
Dim c1 As Boolean
a1 = 12
b1 = 2
c1 = (a1 And b1)
Sheet1.Range("E2").Value = c1
Sheet1.Range("E3").Value = CBool(a1)
Sheet1.Range("e4").Value = CBool(b1)
End Sub





RE: AND Boolean
c1 = ((a1 > 0) And (b1 > 0))
will work.
Doug Jenkins
Interactive Design Services
http://newtonexcelbach.wordpress.com/
RE: AND Boolean
5 AND 2 = False
5 AND 8 = False
5 AND 10 = False
but
5 AND (1,3,4,5,6,7,&9) all evaluate to True
RE: AND Boolean
TTFN
FAQ731-376: Eng-Tips.com Forum Policies
RE: AND Boolean
http://msdn.microsoft.com/en-us/library/wz3k228a%2...
RE: AND Boolean
Sub testand()
Dim a1 As Integer
Dim b1 As Integer
Dim c1 As Boolean
a1 = 12
b1 = 2
c1 = (a1 And b1)
Sheet1.Range("g2").Value = c1
Sheet1.Range("g3").Value = CBool(a1)
Sheet1.Range("g4").Value = CBool(b1)
End Sub
Sub test()
For counter = 0 To 1000
Range("a2").Offset(counter, 0).Value = -500 + counter
Range("a2").Offset(counter, 1).Value = CBool(Range("a2").Offset(counter, 0))
Range("c2").Offset(counter, 0).Value = -510 + counter
Range("c2").Offset(counter, 1).Value = CBool(Range("c2").Offset(counter, 0))
Range("e2").Offset(counter, 0).Value = (Range("e2").Offset(counter, -3).Value And Range("e2").Offset(counter, -1).Value)
Range("f2").Offset(counter, 0).Value
Next
End Sub
RE: AND Boolean
When it comes to convert that integer to a boolean, it takes the view that an integer of zero corresponds to FALSE, and non-zero corresponds to TRUE.
RE: AND Boolean
0 = false
anything else = true
In some languages
0 = false
1 = true
anything else is undefined
In some languages
0 = false
all bits set = true
anything else is undefined
In some languages (eg P/LM), only the Least Significant bit is checked.
0 = false
1 = true
So 4 (100) would be false and 5 (101) would be true.
RE: AND Boolean
No, it doesn't. Incorrect/inappropriate implementation of boolean varies.
TTFN
FAQ731-376: Eng-Tips.com Forum Policies
RE: AND Boolean
=====================================
(2B)+(2B)' ?
RE: AND Boolean
No argument there; but that applies to EVERYTHING that takes an input. This is the source of a multitude of buffer overrun exploits that have plagued many Microsoft programs.
TTFN
FAQ731-376: Eng-Tips.com Forum Policies