Answers to If…ElseIf Exercise
1)
What
output would be produced if the user entered the following numbers in the txtYear TextBox?
Dim intYears As Integer
txtYears.Text
intYears
intVacationWeeks Output
a)
5
5
1
1
b)
6
6
2
2
c)
10
10
2
2
d)
8
8
2
2
e)
12
12
3
3
f)
0
0
0
0
Dim
intVacationWeeks As Integer
intYears = convert.ToInt32(txtYears.Text)
If intYears = 0 Then
intVacationWeeks = 0
ElseIf intYears < 6 Then
intVacationWeeks = 1
ElseIf intYears < 11 Then
intVacationWeeks = 2
Else
intVacationWeeks = 3
End If
Msgbox( “Vacation earned --“ & intVacationWeeks)
2)
txtState.Text strState Output
1) Shipping Charge = $30
2) Shipping Charge = $32.50
3)
Incorrect State
4) Incorrect State Because “c” is not the same as “C” “
What
output would
be produced if
the user entered the following strings in the txtState
TextBox?
Dim strState As String
strState = txtState.Text
If strState = "
Msgbox( "Shipping Charge = $25")
ElseIf strState = "
Msgbox( "Shipping Charge = $30")
ElseIf strState = "
Msgbox( "Shipping Charge = $32.50")
Else
Msgbox( "Incorrect State")
End If