Visual Basic Tracing If Statement Worksheet #1

Visual Basic
Tracing If Statement Worksheet #1
Name_______________________
Period________
Assume that the control expressions listed below fit into the If statement in the following code segment:
intNum = 5
intOther = 10
dblNum = -3
If ( _________________ ) Then
MessageBox.Show("true")
End If
For each of the following exercises, indicate whether the control expression is True or False. Write out the word “True” or “False”.
If a syntax error occurs, write "Error".
___________ 1. intNum > 5
___________ 2. intNum >=5 And intOther < 11
___________ 3. dblNum <> -1 Or intOther < 0
___________ 4. Not (intNum > 3) Or intNum <= 5
___________ 5. Not (intOther >= intNum)
___________ 6. 0 – dblNum > 0
___________ 7. 4 / 2 = intOther / intNum
___________ 8. intOther Mod 2 = 0
___________ 9. intOther + 2 * intNum <> 30 Or Not (dblNum > 0)
___________ 10. intOther > 0 And intNum > 0 Or dblNum > 0
___________ 11. dblNum > 0 Or intNum >= 0 And –1 * intOther = -10
___________ 12. intNum = “5”
___________ 13. intNum > 0 Or dblNum <= 0 And intOther = 13
___________ 14. Not (Not (Not (Not (intNum > 0))))
Writing If Statements Worksheet #1
1. Write an If statement that displays “even” in a message box if the variable intNum is an even number. The same If
statement should display “odd” in a message box if the variable intNum is an odd number. You can assume as a
precondition that intNum is greater than 2.
2. Write an If statement that displays "multiple of 3" in a message box if the variable intNum is a multiple of 3. You can
assume as a precondition that intNum is greater than 3.
3. Write an If statement that displays "yes" in a message box if the variable intNum is a multiple of 3 but it is not a
factor of 24. You can assume as a precondition that intNum is greater than 3.
4. Write an If ElseIf statement that displays “equilateral” in a message box if the variables intSide1, intSide2, and
intSide3 are equal. If exactly two out of three of those variables are equal, the If statement must display “isosceles”
in a message box. Otherwise, display “scalene” in a message box.
5. Write an If statement that displays "yes" in the label named lblOutput if intSum is greater than 5.
6. Change the If statement that you used in your answer to #5 into an If Else statement so that it also displays "no" in
the label if intSum is not greater than 5.
7. Write an If ElseIf statement that:
-displays the message "greater than 5" in lblOutput if intSum is greater than 5,
-displays the message "equal to 5" in lblOutput if intSum is equal to 5,
-and displays the message "less than 5" in lblOutput in all other cases.