' Visual Basic 2008 9.0 .NET Examples - Operators - Introduction to Visual Basic : Module Example7 Sub Main() Dim tamagotchiState As Integer = 5 ' ... If (tamagotchiState And 1) = 1 Then Console.WriteLine("happy") If (tamagotchiState And 2) = 2 Then Console.WriteLine("thirsty") If (tamagotchiState And 4) = 4 Then Console.WriteLine("hungry") ' (1) If (tamagotchiState And 8) = 8 Then Console.WriteLine("tired") Console.WriteLine() ' Console.WriteLine("making tamagotchi not hungry ...") tamagotchiState = tamagotchiState And Not 4 ' (2) Console.WriteLine() ' If (tamagotchiState And 1) = 1 Then Console.WriteLine("happy") If (tamagotchiState And 2) = 2 Then Console.WriteLine("thirsty") If (tamagotchiState And 4) = 4 Then Console.WriteLine("hungry") If (tamagotchiState And 8) = 8 Then Console.WriteLine("tired") Console.WriteLine() ' Console.WriteLine("making tamagotchi thirsty ...") tamagotchiState = tamagotchiState Or 2 ' (3) Console.WriteLine() ' If (tamagotchiState And 1) = 1 Then Console.WriteLine("happy") If (tamagotchiState And 2) = 2 Then Console.WriteLine("thirsty") If (tamagotchiState And 4) = 4 Then Console.WriteLine("hungry") If (tamagotchiState And 8) = 8 Then Console.WriteLine("tired") Console.WriteLine() ' Console.WriteLine("making tamagotchi happy, hungry and tired ...") tamagotchiState = tamagotchiState Or 1 Or 4 Or 8 Console.WriteLine() ' If (tamagotchiState And 1) = 1 Then Console.WriteLine("happy") If (tamagotchiState And 2) = 2 Then Console.WriteLine("thirsty") If (tamagotchiState And 4) = 4 Then Console.WriteLine("hungry") If (tamagotchiState And 8) = 8 Then Console.WriteLine("tired") Console.WriteLine() ' Console.WriteLine("making tamagotchi not hungry and not tired ...") tamagotchiState = tamagotchiState And Not 4 And Not 8 Console.WriteLine() ' If (tamagotchiState And 1) = 1 Then Console.WriteLine("happy") If (tamagotchiState And 2) = 2 Then Console.WriteLine("thirsty") If (tamagotchiState And 4) = 4 Then Console.WriteLine("hungry") If (tamagotchiState And 8) = 8 Then Console.WriteLine("tired") Console.WriteLine() ' Console.WriteLine("inverting states ...") tamagotchiState = Not tamagotchiState Console.WriteLine() ' If (tamagotchiState And 1) = 1 Then Console.WriteLine("happy") If (tamagotchiState And 2) = 2 Then Console.WriteLine("thirsty") If (tamagotchiState And 4) = 4 Then Console.WriteLine("hungry") If (tamagotchiState And 8) = 8 Then Console.WriteLine("tired") ' Console.ReadLine() End Sub End Module ' Visit www.studyvb.com for more examples. Copyright 2003-2008 De Wolf.