Select Case True

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

    After reading this thread, it appears that the primary argument for Select Case True is readability. Is this enough? When I first saw the construct used like this in VB.NET, I had to read over it a few times to make sure I'd got the gist of it, but still thought along the same lines as RolandTumble, above. So even readability comes at a slight cost. Everyone knows what an If...ElseIf...End If statement is and why it's there. Short circuiting can be aided using AndAlso or OrElse, and complexity is purely down to the code and coder involved.

    Even If statements can be optimised. What's the point in asking the obvious (whether your value = True). I was once asked what the following did by a coder working with us...

    Dim isVisible As Boolean
    ....
    If isVisible Then
        ....
    End If
    

    The use of the Select Case True structure also feels like you're moving the focus or the comparison emphasis away from the actual Select Case line and into the Case statements, as odd as that may sound.

提交回复
热议问题