# I have a VB.Net assignment statement with an or clause. What does it mean?

VB.Net

dim a as Boolean = false
dim b as Boolean = true
dim c as Boolean

This line of code confuses me:
c = a or b

I've never seen a line of code like that.  What does it mean?

My best guess is that it means if a is null then set c to equal b, but that's truly a wild guess.  Is this even a valid line of code?
LVL 4
###### Who is Participating?

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Senior .Net ConsultantCommented:
not at all.

is it clearer if you read this:
``````c = (a = true) or (b = true)
``````
Author Commented:
So, I think you are saying that if either a or b is true, c will be true.  Is that correct?

The only way c is false is if both a and b are false.  Still correct?

Thanks!
RetiredCommented:
Hi  g_johnson;

Yes the statements are valid. The variable c will have the boolean value of a Or b. If a or b is Nothing them c will be equal to the value of the other one. If both are Nothing then c will equal False.
Senior .Net ConsultantCommented:
>>So, I think you are saying that if either a or b is true, c will be true.  Is that correct?

correct

>>The only way c is false is if both a and b are false.  Still correct?

False. If a OR b is false, c is set to false.
DeveloperCommented:
@g_johnson; correct, boolean OR equates to:

True OR True = True
False OR True = True
True OR False = True
False OR False = False

Whereas boolean AND equates to:
True AND True = True
False AND True = False
True AND False = False
False AND False = False

We can test this as well:
``````Module Module1
Sub Main()
Console.WriteLine("Let's test Or")
OrTest(True, True)
OrTest(False, True)
OrTest(True, False)
OrTest(False, False)
Console.WriteLine()
Console.WriteLine("Now let's test And")
AndTest(True, True)
AndTest(False, True)
AndTest(True, False)
AndTest(False, False)
End Sub

Sub OrTest(ByVal lhs As Boolean, ByVal rhs As Boolean)
Console.WriteLine("{0} OR {1} = {2}", lhs, rhs, lhs Or rhs)
End Sub

Sub AndTest(ByVal lhs As Boolean, ByVal rhs As Boolean)
Console.WriteLine("{0} AND {1} = {2}", lhs, rhs, lhs And rhs)
End Sub
End Module
``````
Which produces the following output --saige-

Experts Exchange Solution brought to you by

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

DeveloperCommented:
This all stems from a bitwise operation whereas 0 = False and 1 = True.  So changing our program we can  prove at the bit level that the boolean operation is correct:
``````Module Module1
Sub Main()
Console.WriteLine("Let's test Or")
OrTest(1, 1)
OrTest(0, 1)
OrTest(1, 0)
OrTest(0, 0)
Console.WriteLine()
Console.WriteLine("Now let's test And")
AndTest(1, 1)
AndTest(0, 1)
AndTest(1, 0)
AndTest(0, 0)
End Sub

Sub OrTest(ByVal lhs As Short, ByVal rhs As Short)
Console.WriteLine("{0} OR {1} = {2}", lhs, rhs, lhs Or rhs)
End Sub

Sub AndTest(ByVal lhs As Short, ByVal rhs As Short)
Console.WriteLine("{0} AND {1} = {2}", lhs, rhs, lhs And rhs)
End Sub
End Module
``````
Which now produces the following output --saige-
Author Commented:
Thanks, all!
###### It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.