Answer on Question#55280, Programming | Visual Basic
what statement allows many branches or alternative paths?
Solution
Main construction allow many branches is switch... case technology. View of case statement:
Select [ Case ] testexpression
[ Case expressionlist
[ statements ] ]
[ Case Else
[ elsestatements ] ]
End SelectWhere testexpression evaluate to one of the elementary data types
Required in a Case statement. List of expression clauses representing match values for testexpression. Multiple expression clauses are separated by commas. Each clause can take one of the following forms:
- expression1 To expression2
- [Is] comparisonoperator expression
- expression
Use the To keyword to specify the boundaries of a range of match values for testexpression. The value of expression1 must be less than or equal to the value of expression2.
As example: show messages with different information about a corresponding to value a
Sub Test()
a = 3
Select Case a
Case Is > 5
MsgBox "greater than 5"
Case Is > 7
MsgBox "greater than 7"
Case Else
MsgBox "Didn't work any condition"
End Select
End Subhttp://www.AssignmentExpert.com/
Comments