Select Case True

后端 未结 9 1818
失恋的感觉
失恋的感觉 2020-11-27 07:08

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

9条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-27 07:40

    Select Case is a powerful operator by itself. But even though Select Case True is still supported, it is better to be avoided for maintainability perspective. You always have to justify the need. If needed badly, you can even use DoEvents and GoTo. For the accepted answer, it could have been written like this instead:

    Select Case testVariable
      Case Is < 0 : Console.Write("You must supply a non-negative value.")
      Case Is > 10 : Console.Write("Please enter a number from 0-10.")
      Case Else : Call DoWork(testVariable)
    End Select
    

提交回复
热议问题