1.20 - Logical Operators

1... Often in programming, software developers may wish to have more than one condition in an If...Then... Else statement. To do this they use something called Boolean expressions that contain Logical Operators. Examples of these are OR, AND, or NOT.

The boolean expressions will evaluate to being either TRUE or FALSE. To organize the results of boolean expressions, we use truth tables for each of the individual logical operators:

AND
EXPRESSION 1
EXPRESSION 2
RESULT
FALSE
FALSE
FALSE
TRUE
FALSE
FALSE
FALSE
TRUE
FALSE
TRUE
TRUE
TRUE

OR
EXPRESSION 1
EXPRESSION 2
RESULT
FALSE
FALSE
FALSE
TRUE
FALSE
TRUE
FALSE
TRUE
TRUE
TRUE
TRUE
TRUE

NOT
EXPRESSION
RESULT
TRUE
FALSE
FALSE
TRUE

2... To use logical operators in Visual Basic, the code would be similar to the following:

If intAge >= 16 AND strEyeTest = "Pass" Then
lblResult.Text = "You may take your driver's test"
Else
lblResult.Text = "Sorry, you may not take your drivers test"
End If

3... Your task is to create a program for a hospital to determine whether or not a patient is eligible for an operation. In order for the patient to be eligible, they must be above the age of 12 and below the age of 65, they must have type A or type O blood, and they must be over 100 pounds but below 250 pounds. Your program will utilise textboxes to retrieve the information, and will then use a label to output a message indicating whether or not they are eligible for the operation. You may also want to include a MessageBox in case the user does not provide a value for one of the textboxes.