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 |
And |
Or |
0 |
0 |
0 |
0 |
0 |
1 |
0 |
1 |
1 |
0 |
0 |
1 |
1 |
1 |
1 |
1 |
Order of Operations |
Arithmetic |
Exponentiation ( ^ ) |
Negation ( - ) |
*, / |
Mod |
+, - |
Relational |
=, <>, <, >, <=, >= |
Logical |
Not |
And |
Or |
(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
Objective #2: Use If statements to ensure that certain statements are executed only when a given condition applies.
If (lengthOfSideA = lengthOfSideB = lengthOfSideC) Then
MessageBox.Show("equilateral triangle")
End If
If ((lengthOfSideA = lengthOfSideB) And (lengthOfSideB = lengthOfSideC)) Then
MessageBox.Show("equilateral triangle")
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 (age >= 13) Then
MessageBox.Show("You can watch a PG-13 rated movie.")
Else
MessageBox.Show("You can not watch a PG-13 rated movie.")
End if
If (age >= 17) Then
MessageBox.Show("You can watch rated R and rated PG-13 movies.")
ElseIf (age >= 13) Then
MessageBox.Show("You can only watch rated PG-13 movies.")
End If
Objective #4: Use the Mod operator to test divisibility.
24 is evenly divisible by 6 since 24 Mod 6 = 0
100 is evenly divisible by 10 since 100 Mod 10 = 0
8 is evenly divisible by 2 since 8 Mod 2 = 0
9 is evenly divisible by 3 since 9 Mod 3 = 0
The following statement tests to see if 24 is evenly divisible by the variable num
If (24 Mod num = 0) Then
MessageBox.Show("yes")
End If
6 is a factor of 24 since 24 Mod 6 = 0
10 is a factor of 100 since 100 Mod 10 = 0
2 is a factor of 8 since 8 Mod 2 = 0
3 is a factor of 9 since 9 Mod 3 = 0
The following statement tests to see if 4 is a factor of the variable num
If (num Mod 4 = 0) Then
MessageBox.Show("yes")
End If
24 is a multiple of 6 since 24 Mod 6 = 0
100 is a multiple of 10 since 100 Mod 10 = 0
8 is a factor of 2 since 8 Mod 2 = 0
9 is a factor of 3 since 9 Mod 3 = 0
The following statement tests to see if 24 is a multiple of the variable num
If (24 Mod num = 0) Then
MessageBox.Show("yes")
End If
6 is a divisor of 24 since 24 Mod 6 = 0
10 is a divisor of 100 since 100 Mod 10 = 0
2 is a divisor of 8 since 8 Mod 2 = 0
3 is a divisor of 9 since 9 Mod 3 = 0
The following statement tests to see if 3 is a divisor of the variable num
If (num Mod 3 = 0) Then
MessageBox.Show("yes")
End If