Results 1 to 5 of 5

Thread: [RESOLVED] [2008] Select Case multiple clauses

  1. #1

    Thread Starter
    Registered User nmadd's Avatar
    Join Date
    Jun 2007
    Location
    U.S.A.
    Posts
    1,676

    Resolved [RESOLVED] [2008] Select Case multiple clauses

    I don't think I can do this, but I thought I would confirm with my most trusted VB source - you!

    vb.net Code:
    1. Select Case i
    2.     Case 1, 2, 3
    3.         DoSomething()
    4. End Select

    Can I tell if 1, 2, or 3 got me to DoSomething()?

  2. #2
    PowerPoster JuggaloBrotha's Avatar
    Join Date
    Sep 2005
    Location
    Lansing, MI; USA
    Posts
    4,286

    Re: [2008] Select Case multiple clauses

    Inside the Case 1, 2, 3 you would have to check for what i is again to tell which caused it to step into that case

    you'd be better off not testing for 1, 2, 3 and simply do a case for each

    ie
    Code:
    Select Case i
      Case 1
        Something
      Case 2
        Something
      Case 3
        And Something
    End Select
    Currently using VS 2015 Enterprise on Win10 Enterprise x64.

    CodeBank: All ThreadsColors ComboBoxFading & Gradient FormMoveItemListBox/MoveItemListViewMultilineListBoxMenuButtonToolStripCheckBoxStart with Windows

  3. #3

    Thread Starter
    Registered User nmadd's Avatar
    Join Date
    Jun 2007
    Location
    U.S.A.
    Posts
    1,676

    Re: [2008] Select Case multiple clauses

    Fair enough. Thanks!

  4. #4
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: [RESOLVED] [2008] Select Case multiple clauses

    Code:
    For testCTR As Integer = 0 To 10
                Select Case testCTR
                    Case 0, 1, 2
                        Debug.WriteLine(testCTR.ToString.PadRight(3, " "c) & "0, 1 or 2")
                    Case 3
                        Debug.WriteLine(testCTR.ToString.PadRight(3, " "c) & "3")
                    Case 4 To 7
                        Debug.WriteLine(testCTR.ToString.PadRight(3, " "c) & "4 - 7")
                    Case Else
                        Debug.WriteLine(testCTR.ToString.PadRight(3, " "c) & "other")
                End Select
            Next
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  5. #5
    PowerPoster JuggaloBrotha's Avatar
    Join Date
    Sep 2005
    Location
    Lansing, MI; USA
    Posts
    4,286

    Re: [RESOLVED] [2008] Select Case multiple clauses

    Quote Originally Posted by dbasnett
    Code:
    For testCTR As Integer = 0 To 10
                Select Case testCTR
                    Case 0, 1, 2
                        Debug.WriteLine(testCTR.ToString.PadRight(3, " "c) & "0, 1 or 2")
                    Case 3
                        Debug.WriteLine(testCTR.ToString.PadRight(3, " "c) & "3")
                    Case 4 To 7
                        Debug.WriteLine(testCTR.ToString.PadRight(3, " "c) & "4 - 7")
                    Case Else
                        Debug.WriteLine(testCTR.ToString.PadRight(3, " "c) & "other")
                End Select
            Next
    That still doesn't help him any, once he's inside the case of 1, 2 or 3, he'll still have to test i again to find out if it stepped in because i was a 1, 2 or a 3.
    Currently using VS 2015 Enterprise on Win10 Enterprise x64.

    CodeBank: All ThreadsColors ComboBoxFading & Gradient FormMoveItemListBox/MoveItemListViewMultilineListBoxMenuButtonToolStripCheckBoxStart with Windows

Posting Permissions

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



Click Here to Expand Forum to Full Width