MF Luder
MF Luder

Reputation: 379

VB.NET Select Case Perform All Case Options?

In a Select Case statement, is there an easy way to tell it that for Case Else, I want it to do all of the actions specified in all of the other Case options? I know I can just copy the relevant code, but I'm looking for a simpler, cleaner solution.

SELECT CASE answer
   CASE "1"
    *Do something*

   CASE "2"
    *Do something else*

   Case "3"
    *Do all actions in CASE 1 and in Case 2*
END SELECT

Upvotes: 1

Views: 554

Answers (1)

Nalaka526
Nalaka526

Reputation: 11464

PRIVATE SUB YourMethod()
   SELECT CASE answer
       CASE "1"
           Method1()

       CASE "2"
           Method2()

       Case "3"
           Method1()
           Method2()
    END SELECT
END SUB

PRIVATE SUB Method1()
   *Do something*
END SUB

PRIVATE SUB Method2()
   *Do something else*
END SUB

Upvotes: 3

Related Questions