Select case / case is, multiple arguments

  • Thread starter Werner Rohrmoser
  • Start date
W

Werner Rohrmoser

Hi,

I'd like to know whether it is possible to code the structure below
direct
and not indirect as I have done it.
Something like "Case Is <> 3, Is <> 6, Is <> 9".

Example:
'************************************************************************
Option Explicit
Option Compare Text

Public Sub DoingSomethingExceptItIs_3_OR_6_OR_9()

Dim LoopCounter As Integer

For LoopCounter = 1 To 10
Select Case LoopCounter
Case 3, 6, 9
Case Else
MsgBox LoopCounter
End Select
Next LoopCounter

End Sub
'*********************************************************************

Thanks for your Support
Werner
 
M

Martin Fishlock

The select case statement checks each expression on the expressionlist and if
it meets the criteria then it has satisified the requirments and processes
the code for that item.

Therefore you cannot do 'AND' type expressions and you will have to stay
with the code you have or use if statements as in

Sub case369(i As Integer)
If Not (i = 3 Or i = 6 Or i = 9) Then
Debug.Print True
Else
Debug.Print False
End If
End Sub
 
B

Bob Phillips

You can do this

Public Sub DoingSomethingExceptItIs_3_OR_6_OR_9()

Dim LoopCounter As Integer

For LoopCounter = 1 To 10
Select Case True
Case LoopCounter Mod 3 <> 0
MsgBox LoopCounter
End Select
Next LoopCounter

End Sub


--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top