Select Case True

Otávio Décio picture Otávio Décio · Apr 27, 2009 · Viewed 30.7k times · Source

Apparently this used to be a way in VB6 and VBA to short circuit and execute the first true case:

Select Case True
End Select

Is this still in use (VB.NET) ?

Answer

Chad Birch picture Chad Birch · Apr 27, 2009

This syntax is often used instead of an If...ElseIf statement. Some people find it a little easier to read. For example:

Select Case True
    Case testVariable < 0
         Console.Write("You must supply a positive value.")
    Case testVariable > 10
         Console.Write("Please enter a number from 0-10.")
    Case True
         Call DoWork(testVariable)
End Select

The answer is that yes, this still works in VB.NET. Just take care with when you use it, because it's not a "standard programming construct" and may be unfamiliar to people that have to maintain your code in the future.