Select - Case
Executes one of several groups of statements, depending on the value of an expression.
When using a Select-Case statement always put the most likely candidates at the top of the list. This will help performance.
If you use only one instruction per case you can put the instructions on the same line using a colon.
Select Case sText
Case "Match 1": Call Proc1()
Case "Match 2": Call Proc2()
Case Else: Call Proc3()
If you want to execute more than one instruction then put the instructions below the case statement.
You can combine a series of tests in a single case statement by separating them with commas.
Select Case X
Case 1 To 5 : statement 1
Case 6, 7, 8
Case Is = 6 : statement 4
Case Is >= 12 : statement 5
Case Is > 8 And Is < 11
Case 10 To 15, 15 To 20 : statement 8
Case "better": statement 9
Case Is < "A" : statement 10
Case Is > "solutions": statement 11
Case Else: statement 12
If no Case expression matches the value of the identifier than execution continues at the statement following the End Select
Similar to numbers, text values can also be grouped.
The default or when Option Compare Binary is specified is a case sensitive comparison: A < B < Z < a < b < z
This cannot be done
Case Is > 8 Or Is < 11
Select Case statements can be nested, as long as each Select Case has a corresponding End Select.
The SWITCH function returns values based on expressions.
This provides an alternative to the Select-Case.
© 2020 Better Solutions Limited. All Rights Reserved. © 2020 Better Solutions Limited TopPrevNext