Select Case True

后端 未结 9 1826
失恋的感觉
失恋的感觉 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:34

    Others have already answered that actual question, but I just want to chime in that I use this construct fairly frequently. I think it's often the most readable way of simultaneously testing two boolean conditions:

    Dim A As Boolean
    Dim B As Boolean
    '
    'do stuff to set values of A and B
    '
    Select Case True
      Case A And B
        'something
      Case A And Not B
        'something else
      Case Not A And B
        'you get the picture
      Case Else
        '...
    End Select
    

    I admit that part of why I find it easily readable is that I do use it, and that I do recall having to parse it the first time I saw it--but once successfully parsed, my reaction was "That's brilliant!"

提交回复
热议问题