When performing multiple comparisons it is easy to get trapped into using multiple If-ElseIf statements. While that will certainly accomplish the task a cleaner, and more efficient, way to do this is to use the Select Case construct. Examples of the same comparison are shown below. In the Select Case example notice that you are not limited to comparing a single variable.
If-ElseIf
If iStart < 0 Then
‘Do something here
ElseIf iStart > iEnd Then
‘Do something here
ElseIf iCount = iStart Then
‘Do something here
ElseIf iCount = iEnd Then
‘Do something here
Else
‘Do something here
End If
|
Select Case
Select Case True
Case (iStart < 0)
‘Do something here
Case (iStart > iEnd)
‘Do something here
Case (iCount = iStart)
‘Do something here
Case (iCount = iEnd)
‘Do something here
Case Else
‘Do something here
End Select
|