jeudi 27 juillet 2017

VBA - IF evaluation

I am pretty sure that in most languages you can secure the evaluation of a condition by doing one of the following:

if FALSE and (1/0 = 0) {...}

or

if TRUE or (1/0 = 0) {...}

Those examples should not throw exeptions (maybe the second one depending on internal implementation of the evaluation) as the whole if-condition is met even without checking the second condition.

In VBA however both these protections wont work:

If False and t() Then ...
If True or t() Then ...

Function t() As Boolean
MsgBox "This is displayed both times"
End Function

Why does VBA behave this way and what is the best (+shortest) way to do these kind of protections instead?

Example: If s = "" or thisFunctionCantTakeEmptyStrings(s) Then ...

Aucun commentaire:

Enregistrer un commentaire