Page

4.3.4- Logical Operators

  by NT Community Manager.
Last Updated  by Joel Bush.  

PublicCategorized as 04. Variables.

Not tagged.
<< 4.3.3- Arithmetic CalculationsChapter44.3.5- Concatenating Variables >>

Logical Operators

There's also a set of logical operators you can use in your code:

 

AND

OR

NOT

 

Actually there are more than three logical operators, but they're only required in specialist situations, so we won't be using them in this book. The logical operators are used in the same way as comparison operators and also return a Boolean value:

 

If intNumber1 = 1 AND intNumber2 = 2 Then

 

They are used to determine a particular course of action. When using AND, both of these conditions have to be TRUE for the condition to be fulfilled. This differs from OR where only one out of the two conditions has to be TRUE for the condition to be fulfilled. If both conditions are true, the condition will also be true

 

If Number1 = 1 OR Number2 = 2 Then

 

The third logical operator NOT, simply implies the reverse of the condition. If Number1 isn't equal to 1 then the condition is fulfilled:

 

If NOT Number1=1 Then

 

There is a precedence for these logical operators in the way that they are calculated. This is:

 

  • NOT
  • AND
  • OR

 

Take the following example:

 

If Number1=1 OR NOT Number2=1 AND NOT Number 3=1 Then

 

Here the second part of the expression would be calculated first. You would check to see if Number2 wasn't equal to one and Number3 wasn't equal to one, before going back and checking to see if Number1 is equal to 1.

 

<< 4.3.3- Arithmetic CalculationsChapter44.3.5- Concatenating Variables >>

Copyright © 2003 by Wiley Publishing, Inc.

Powered by Near-TimeTerms of Services | Privacy Policy | Security Policy |