Visual Basic Chapter 8 Quiz
Multiple Choice
Identify the letter of the choice that best completes the statement or answers the question.
1. Which of the following code segments assigns the string “Great Year” to the Text property of a label named lblMessage when the value in the variable decSales is either greater than 50,000 or equal to 50,000?
a. If decSales > 50000 Then
lblMessage.Text = “Great Year”
End If
b. If decSales >= 50000 Then
lblMessage.Text = “Great Year”
End If
c. If decSales < 50000 Then
lblMessage.Text = “Great Year”
End If
d. If decSales <= 50000 Then
lblMessage.Text = “Great Year”
End If
2. Suppose you want to determine whether a variable, decPayAmount, is between 1200 and 1400, inclusively. If it is, you want to set lblMessage text to “Pay amount is in the range”. Which of the following code segments will accomplish this?
a. If decPayAmount <= 1200 And decPayAmount>= 1400 Then
lblMessage.Text = “Pay amount is in the range”
End If
b. If decPayAmount <=1200 Or decPayAmount >= 1400 Then
lblMessage.Text = “Pay amount is in the range”
End If
c. If decPayAmount >=1200 And decPayAmount <=1400 then
lblMessage.Text = “Pay amount is in the range”
End If
d. If decPayAmount > 1200 Or decPayAmount < 1400 Then
.Text = “Pay amount is in the range”
End If
3. What value is assigned to decTaxes by the following program segment, assuming that the user enters 50000 into the textbox txtSalary.Text?
Dim decSalary As Decimal
Dim decTaxes As Decimal
decimal.TryParse(txtSalary.Text, decSalary)
If (decSalary > 50000) Then
decTaxes = .40 * decSalary
ElseIf (decSalary > 40000) Then
decTaxes = .30 * decSalary
ElseIf (decSalary > 30000) Then
decTaxes = .20 * decSalary
Else
decTaxes = .10 * decSalary
End If
a. 20000 b. 15000 c. 10000 d. 5000
4. Which change would correct the syntax error in the following code?
1: If intScore < 80 Then
2: strGrade = "C"
3: Else intScore > 80 Then
4: strGrade = "A"
5: End If
a. 1: If( intScore < 80 ) Then
b. 2: Set strGrade = "C"
c. 3: ElseIf intScore > 80 Then
d. none of the above correct the syntax error
5. What value will be assigned to strGrade when intScore equals 90?
If intScore > 60 Then
strGrade = “D”
End If
If intScore > 70 Then
strGrade = “C”
End If
If intScore > 80 Then
strGrade = “B”
End If
If intScore > 90 Then
strGrade = “A”
End If
a. A / b. B / c. C / d. D6. The expression Integer.TryParse(“12.5”, intNbr) performs the following:
a. Returns True
b. Returns False
c. Places the value 12.5 in the variable intNbr
d. Returns True and places the value 12.5 in the variable intNbr
7. What is the scope of a variable declared in a selection structure’s false path?
a. the entire application
b. the procedure containing the selection structure
c. the entire selection structure
d. only the selection structure’s false path
8. Assume x is 5, y is 6, and zis 8, indicate whether each of the following relational expressions equals True or False
a. x = 5 / T / F / e. z > 4 / T / Fb. 7<= (x+2) / T / F / f. x >= 6 / T / F
c. z < 4 / T / F / g. x <= (y*2) / T / F
d. (2+x) > y / T / F / h. (10-x) < (z-y) / T / F