唯一的短路(某种程度上)是在Case表达式求值内,因此以下令人费解的语句可以满足我的要求。Select Case True Case (myObject Is Nothing), Not myObject.test() MsgBox "no instance or test == false" Case Else MsgBox "got instance & test == true" End SelectEnd Sub
这是一个古老的问题,但是这个问题仍然存在。我使用的一种解决方法:Dim success As Boolean ' False by default.If myObj Is Nothing Then ' Object is nothing, success = False already, do nothing.ElseIf Not myObj.test() Then ' Test failed, success = False already, do nothing.Else: success = True ' Object is not nothing and test passed.End IfIf success Then ' Do stuff...Else ' Do other stuff...End If这基本上颠倒了原始问题的逻辑,但是您得到的结果相同。我认为这是一个比仅使用If语句的解决方案更干净的解决方案。使用Select语句的解决方案很聪明,但是如果您只想使用If语句来替代,我认为这是可以使用的解决方案。