Visual Basic Questions and Answers – Multiple Alternative Selection Structures

This set of Visual Basic Multiple Choice Questions & Answers (MCQs) focuses on “Multiple Alternative Selection Structures”.

1. Selection structures that can select from many alternatives are known as __________
a) Selection structures
b) Multiple-alternative selection structures
c) Multiway selection structures
d) Multipath selection structures
View Answer

Answer: b
Explanation: At times you need to create selection structures that can select from many alternatives. Such selection structure is known as multiple-alternative selection structures. For example, a selection structure that displays message based on a letter grade entered by the user.

2. What will be contained in Msg if grade entered by user is ‘d’?

If grade==”A”
    Msg =”Excellent”
ElseIf grade==”B”
    Msg=”Very Good”
ElseIf  grade==”C”
    Msg=”Good”
ElseIf grade==”D”
    Msg=”Fair”
Else
    Msg=”Fail”
EndIf

a) Fair
b) Fail
c) Good
d) Excellent
View Answer

Answer: b
Explanation: Since the grade entered by user does not match any of the alternatives, thus it will enter else part and print “Fail”; even though the user has entered ‘d’; it won’t enter the part grade==”D” since it is case-sensitive. Thus either the user should enter D or we need to add a line as grade.Text.toUpper so that the user does not face any problem, even though he enters ‘d’ instead of “D”.
advertisement
advertisement

3. What will be contained in Msg if grade entered by user is ‘d’?

Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!
grade=grade.Text.ToUpper
If grade==”A”
  Msg =”Excellent”
ElseIf grade==”B”
  Msg=”Very Good”
ElseIf  grade==”C”
  Msg=”Good”
ElseIf grade==”D”
  Msg=”Fair”
Else
  Msg=”Fail”
EndIf

a) Fair
b) Fail
c) Good
d) Excellent
View Answer

Answer: a
Explanation: In this case even though the user enters ‘d’ instead of “D”, it is converted to “D”, by the first line that is grade.Text.ToUpper, thus the user will not face any problem. The ElseIf statement satisfies, and thus Msg contain “Fair”.
advertisement

4. Which is an easier alternative of multiple-alternative selection structure?
a) Single-alternative selection structure
b) Multipath selection structure
c) Select case Statement
d) Multiway-alternative selection structure
View Answer

Answer: c
Explanation: When a multiple-alternative selection structure has many paths from which to choose, it is often simpler and clearer to code the selection structure using the Select Case statement rather than several If…Then…Else statements.

5. The select case statement ends with __________
a) Select End clause
b) End Select clause
c) End clause
d) Select clause
View Answer

Answer: b
Explanation: The Select Case statement ends with end Select clause. The syntax of the Select Case statement is as follows:

advertisement
Select Case SelectorExpression
Case Expnumber
   Instruction to the first case
Case Expnumber
   Instruction to the second case
Case Expnumber
   Instruction to the third case
Case Else
   Instruction when the SelectorExpression does not match
End Select

6. Which of the following Case clauses is invalid in a Select Case statement whose selectorExpression is an Integer variable named intCode?
a) Case Is>7
b) Case 3,5
c) Case 1 to 4
d) Case “A”
View Answer

Answer: d
Explanation: The expression in the Case clause, can be an integer, since the selectorExpression is an integer or a range. Thus all the cases such as, Case 1to 4 is a range is valid, since, a case clause cannot have a condition, can have two integers with commas thus case 3, 5 is valid but cannot have a string since selectorExpression is an integer. Each Case clause represents a different path that the computer can follow.

7. __________ must be the last clause in the Select Case statement.
a) Case Else
b) Case expnumber
c) Case seletorExpression
d) Case default
View Answer

Answer: a
Explanation: You can have as many Case clauses as necessary in a Select Case statement. However, if the Select Case statement includes a Case Else clause, the Case Else clause must be the last clause in the statement. Each of the individual Case clauses, except the Case Else clause, must contain an expressionList, which can include one or more expressions.

8. What will be in text, if Intid contains 2?

Select Case Intid
Case 1
  Text=”Jannet”
Case 2 to 4
  Text=”Mark”
Case 5, 7
  Text=”Jerry”
Case Else
  Text=”Sue”
End Select

a) Jannet
b) Mark
c) Jerry
d) Sue
View Answer

Answer: b
Explanation: When Intid contains 2, it will enter the case 2 to 4, since it means anything between 2 to 4 will enter this case, thus, text will contain Mark.

9. What will be in text, if Intid contains 3?

Select Case Intid
Case 1
  Text=”Jannet”
Case 2 to 4
  Text=”Mark”
Case 5, 7
  Text=”Jerry”
Case Else
  Text=”Sue”
End Select

a) Jannet
b) Mark
c) Jerry
d) Sue
View Answer

Answer: b
Explanation: When Intid contains 2, it will enter the case 2 to 4, since it means anything between 2 to 4 will enter this case, thus, text will contain Mark. Since 3 is between 2 and 4 thus it will enter this case and thus text will contain Mark.

10. What will be in text, if Intid contains 6?

Select Case Intid
Case 1
  Text=”Jannet”
Case 2 to 4
  Text=”Mark”
Case 5, 7
  Text=”Jerry”
Case Else
  Text=”Sue”
End Select

a) Jannet
b) Mark
c) Jerry
d) Sue
View Answer

Answer: d
Explanation: Since none of the cases satisfy 6, thus it will enter the Case Else part and thus the text will contain Sue. If any of the cases would have satisfied, it would have entered there and come out of the Select Case statement.

Sanfoundry Global Education & Learning Series – Visual Basic.

To practice all areas of Visual Basic, here is complete set of 1000+ Multiple Choice Questions and Answers.

If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.