Cor said:
You are real a case select user, nothing wrong with your code (it is even
very nice with that test for the first row)
Yeah, I really do use Select Case as much as possible. First, I find
that the code is much more readable (it uses fewer lines and has less
staggered indentation). For situations where there may be quite a few
possible options, it also gives the compiler a chance to optimize the
branching, as opposed to performing umpteen consecutive If statements.
Second, it may improve performance in other ways. If I do "Select Case
MyProperty," it only has to retrieve the value of MyProperty once. With "If
MyProperty = A ... ElseIf MyProperty = B...", it has to reevaluate it for
every test. You have no way of knowing how complex that property may be, so
the alternative is to cache a local copy before each If statement to get the
same benefit. That's extra code that just clutters things up.
Third, it also gives the reader some extra hints about what's being
done. If you see "Select Case myVariable," you know that the only value
that matters for all of the Case statements is myVariable. With a bunch of
If/ElseIf statements, you have to look at every case, because there may be
some weird exception hidden in there somewhere.
Jeremy