Exclusive OR question

F

Frederick Chow

Hi all,

Sorry first that my question may not be specifically related to Excel VBA,
but I really encountered it when I had to write a VBA function.

Suppose I have three boolean variables A, B and C. How can I test if there
is exactly one of them is true? I found that the following expression

A Xor B Xor C

failed when A = True and B = True and C = True.

Any ideas would be greatly appreciated.

Frederick Chow
Hong Kong.
 
B

Bob Phillips

If Not ((a And b) Or (a And c) Or (b And c)) Then


--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)
 
G

Guest

Hi

VBA stores false as 0 and true as -1. You can declare an interger variable
and set it to A+B+C if the result is -1 only one is true.
 
F

Frederick Chow

Frederick Chow said:
Hi all,

Sorry first that my question may not be specifically related to Excel VBA,
but I really encountered it when I had to write a VBA function.

Suppose I have three boolean variables A, B and C. How can I test if there
is exactly one of them is true? I found that the following expression

A Xor B Xor C

failed when A = True and B = True and C = True.

Any ideas would be greatly appreciated.

Frederick Chow
Hong Kong.
 
B

Bob Phillips

The one I didn't try - <g>

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)
 
D

Dana DeLouis

Suppose I have three Boolean variables A, B and C. How can I test if there
is exactly one of them is true?
A Xor B Xor C

Would this idea work?

bJustOne = (a Or b) Xor c
 
D

Dana DeLouis

Please disregard! I didn't mean to send that, as it is not correct.

Dana DeLouis

<snip>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top