Results 1 to 6 of 6

Thread: Perform all cases in case statement

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2004
    Posts
    541

    Perform all cases in case statement

    Hi all,

    Is there a way to make a VB case statement evaluate all the cases? Similar to a java switch statement (without the break).

    Thanks,

    Strick

  2. #2
    Fanatic Member stlaural's Avatar
    Join Date
    Sep 2007
    Location
    Quebec, Canada
    Posts
    683

    Re: Perform all cases in case statement

    I would say there is not way in vb.net to do this using a select case statement. here's what we find on MSDN :
    "If testexpression matches any Caseexpressionlist clause, the statements following that Case statement are executed up to the next Case statement or the End Select statement. Control then passes to the statement following End Select. If testexpression matches an expressionlist clause in more than one Case clause, only the statements following the first match are executed."

    I' guess you would need to use multiple "if" statement to do what you need.
    Alex
    .NET developer
    "No. Not even in the face of Armageddon. Never compromise." (Walter Kovacs/Rorschach)

    Things to consider before posting.
    Don't forget to rate the posts if they helped and mark thread as resolved when they are.


    .Net Regex Syntax (Scripting) | .Net Regex Language Element | .Net Regex Class | DateTime format | Framework 4.0: what's new
    My fresh new blog : writingthecode, even if I don't post much.

    System: Intel i7 920, Kingston SSDNow V100 64gig, HDD WD Caviar Black 1TB, External WD "My Book" 500GB, XFX Radeon 4890 XT 1GB, 12 GBs Tri-Channel RAM, 1x27" and 1x23" LCDs, Windows 10 x64, ]VS2015, Framework 3.5 and 4.0

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2004
    Posts
    541

    Re: Perform all cases in case statement

    Hi,

    Thanks for your reply. Figured as much just thought I'd ask. If statements it is then...

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

    Re: Perform all cases in case statement

    If <Case1> Then
    End If
    If <Case2> Then
    End If
    'Repeat
    Currently using VS 2015 Enterprise on Win10 Enterprise x64.

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

  5. #5
    Fanatic Member
    Join Date
    Dec 2009
    Posts
    904

    Re: Perform all cases in case statement

    if there is no break; statement in a case statement then all the case statement might evaluate by default

  6. #6
    Frenzied Member stateofidleness's Avatar
    Join Date
    Jan 2009
    Posts
    1,780

    Re: Perform all cases in case statement

    how about using "Finally" after all your cases? put all the code you want to execute in the Finally block.

    i'm curious though, if you're trying to execute ALL the cases, why even have the Select/Case structure? wouldn't you just... 'do' it all minus all the Select/Case code?

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