Wyo VB Lecture Notes
Objective #1: Write Boolean expressions.
| > | greater than |
| < | less than |
| >= | greater than or equal to |
| <= | less than or equal to |
| = | equal to |
| <> | not equal to |
And......
Or.......
Not
|
A |
B |
A And B |
A Or B |
|
0 |
0 |
0 |
0 |
|
0 |
1 |
0 |
1 |
|
1 |
0 |
0 |
1 |
|
1 |
1 |
1 |
1 |
(x > 0) evaluates
to True since x is greater than 0
(x <> 1) evaluates
to False since x is not equal to 1
((x > 5) Or (y <= 20)) evaluates
to True since y is less than or equal to 20 (even though x is not greater than 5)
((Not (x = 12)) And (y = 13)) evaluates
to True since x is not equal to 12 and y is equal to 13
"When several operations occur in an expression, each part is evaluated and resolved in a predetermined order. That order is known as operator precedence. Parentheses can be used to override the order of precedence; that is, they are evaluated in the left to right order in which they appear. Arithmetic and logical operators are evaluated in the following order of precedence:
|
Order of Operations of various kinds of operators in Visual Basic |
||||
|
Arithmetic |
|
Relational |
|
Logical |
|
|
||||
| Exponentiation (^) | Equality | Not | ||
| Negation (-) | Inequality (<>) | And | ||
| Multiplication and division (*, /) | Less than (<) | Or | ||
| Integer division (\) | Greater than (>) | Xor | ||
| Modulus arithmetic (Mod) | Less than or Equal to (<=) | Eqv | ||
| Addition and subtraction (+ and -) | Greater than or Equal to (>=) | Imp | ||
| String concatenation (& or + in some situations ) | Like | |||
| Is | ||||
The string concatenation operator is not an arithmetic operator, but in precedence it does fall after all arithmetic operators and before all comparison operators. Similarly, the Like operator, while equal in precedence to all comparison operators, is actually a pattern-matching operator. The Is operator is an object reference comparison operator. It does not compare objects or their values; it checks only to determine if two object references refer to the same object."
You probably will not have to use the Like, Is, Xor, Eqv, and Imp operators very often, however the information above may still be useful to you. Those operators will not be covered on tests or quizzes for this course.
Objective #2: Use If statements to ensure that certain statements are executed only when a given condition applies.
If (dblSideA = dblSideB = dblSideC) Then
lblTypeOfTriangle.Text = "Equilateral"
End If
If ((dblSideA = dblSideB) And (dblSideB = dblSideC)) Then
lblTypeOfTriangle.Text = "Equilateral"
End If
Objective #3: Use If Else and If ElseIf statements to select which of two sequences of statements will be executed, depending on whether a given condition is TRUE or FALSE.
If (strLightStatus = "On") Then
lblLight.Text = "The light is on."
Else
lblLight.Text = "The light is off."
End if
If (strTrafficLightStatus = "Red") Then
lblLight.Text = "The light is red."
ElseIf (strLightStatus = "Yellow") Then
lblLight.Text = "The light is yellow."
End If
Objective #4: Use the Mod operator to test divisibility.
15 Mod 4 = 3 because 15 divided by 4 leaves a remainder of 3
24 Mod 5 = 4 because 24 divided by 5 leaves a remainder of 4
30 Mod 10 = 0 because 30 divided by 10 leaves a remainder of 0
8 Mod 8 = 0 because 8 divided by 8 leaves a remainder of 0
"any number" Mod 1 = 0 because any number divided by 1 leaves a remainder of 0
"any even number" Mod 2 = 0 because any even number divided by 2 leaves a remainder of 0
"any odd number" Mod 2 = 1 because any odd number divided by 2 leaves a remainder of 1
You could say that the rule is "when the Mod of two numbers is zero, then the first number is evenly divisible by the second number." Or, one could say that "when the Mod of two numbers is zero, then the first number is a multiple of the second number."
Objective #5: Use Select Case statements for multiple selection.