Reputation: 370
Does WorksheetFunction.Or
evaluate all arguments, or does it immediately return True
once an argument evaluates to True
?
The thing is, I am trying to check if a variable is numeric, and if it is, I want to check if it is less than 1. You can see it below:
If IsNumeric(lvl) Or lvl < 1 Then
Do sth...
End If
Described here, the Or
operator in VBA evaluates all arguments and I get Type Mismatch Error when _lvl_
is not numeric. Does WorksheetFunction.Or
behave the same?
Upvotes: 0
Views: 389
Reputation: 78183
Yes, WorksheetFunction.Or
behaves the same.
The reason being, it is a regular function as far as VBA is concerned, so VBA will evaluate all arguments before passing them to the function. The function will not have a chance to perform lazy evaluation.
In order for lazy evaluation to kick in, the evaluation construct must be a part of the language syntax. VBA does not have it in its syntax, so it's not going to work when calling any function in any way.
Upvotes: 2