Why in the world am I getting a message box saying "You should never see this message." followed by a message box saying "You should see this message."
Am I missing something, or does this prove VBA in an "or" statement, keeps testing after it's found a true, rather than stopping where it should?
If so, WTF? Isn't it pretty standard by now that (current) languages stop processing Or statements once they know it's true, at least to save execution time? Is there a reason why Access VBA acts differently? This was fun, wasted a decent amount of time today figuring this one out.
I'm testing this just by typing in the following code, clicking into the subroutine TheTest() and clicking "Run Sub/UserForm".
I can, of course, get around this by re-writing TheTest() to be:
Am I missing something, or does this prove VBA in an "or" statement, keeps testing after it's found a true, rather than stopping where it should?
If so, WTF? Isn't it pretty standard by now that (current) languages stop processing Or statements once they know it's true, at least to save execution time? Is there a reason why Access VBA acts differently? This was fun, wasted a decent amount of time today figuring this one out.
I'm testing this just by typing in the following code, clicking into the subroutine TheTest() and clicking "Run Sub/UserForm".
Code:
Function ReturnTrue() As Boolean
ReturnTrue = True
End Function
Function ThisShouldNotRun() AS Boolean
MsgBox ("You should never see this message.")
ThisShouldNotRun = True
End Function
Sub TheTest()
If (ReturnTrue()) Or (ThisShouldNotRun()) Then
MsgBox ("You should see this message.")
End If
End Sub
I can, of course, get around this by re-writing TheTest() to be:
Code:
Sub TheTest()
If ReturnTrue() Then
MsgBox ("You should see this message.")
ElseIf TestOr() Then
MsgBox ("You should never see this message, either.")
End If
End Sub