G
Geoff Edwards
This is a repeat of a message which I had posted to word97vba - but
then I realised that it is beginners stuff.
Please ignore the other copy.
To test (for example) a series of option buttons I have always used If
... ElseIf thus:
If Opt1 Then
.....
ElseIf Opt2 Then
.......
ElseIf Opt3 Then
.......
Else ' must be Opt4
......
EndIf
A colleague uses:
Select Case True
Case Opt1
.....
Case Opt2
.....
Case Opt3
....
Case Else 'must be Opt4
....
End Select
The Select Case looks a lot neater.
I know that the conventional wisdom appears to be to use Select Case
to test an object or variable for various values, and If... to test
various objects for a value (or values) but is there any reason not to
use (eg) Select Case True?
It is even neater when you use it like this to check whether a few
variables are empty:
Select Case ""
Case var1, var2, var3
....
Case Else
....
End Select
Which is so much neater than:
If var1="" Or var2="" or var3="" then
Is there anything wrong with using this technique?
Geoff Edwards
Leeds, UK
e-mail: (e-mail address removed)
(replace the stopspambot bit with some
version of my name)
then I realised that it is beginners stuff.
Please ignore the other copy.
To test (for example) a series of option buttons I have always used If
... ElseIf thus:
If Opt1 Then
.....
ElseIf Opt2 Then
.......
ElseIf Opt3 Then
.......
Else ' must be Opt4
......
EndIf
A colleague uses:
Select Case True
Case Opt1
.....
Case Opt2
.....
Case Opt3
....
Case Else 'must be Opt4
....
End Select
The Select Case looks a lot neater.
I know that the conventional wisdom appears to be to use Select Case
to test an object or variable for various values, and If... to test
various objects for a value (or values) but is there any reason not to
use (eg) Select Case True?
It is even neater when you use it like this to check whether a few
variables are empty:
Select Case ""
Case var1, var2, var3
....
Case Else
....
End Select
Which is so much neater than:
If var1="" Or var2="" or var3="" then
Is there anything wrong with using this technique?
Geoff Edwards
Leeds, UK
e-mail: (e-mail address removed)
(replace the stopspambot bit with some
version of my name)