+ Reply to Thread
Results 1 to 3 of 3

Select case / case is, multiple arguments

  1. #1
    Werner Rohrmoser
    Guest

    Select case / case is, multiple arguments

    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


  2. #2
    Martin Fishlock
    Guest

    RE: Select case / case is, multiple arguments

    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

    --
    HTHs Martin


    "Werner Rohrmoser" wrote:

    > 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
    >
    >


  3. #3
    Bob Phillips
    Guest

    Re: Select case / case is, multiple arguments

    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)

    "Werner Rohrmoser" <[email protected]> wrote in message
    news:[email protected]...
    > 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
    >




+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1