devxlogo

Avoid IIf Inefficiencies

Avoid IIf Inefficiencies

The IIf function-which returns one of two values determined by logical test-has this syntax: IIf(Expression, TruePart, FalsePart). At first, it might seem like an ideal shortcut for an If…Else…End If block. However, IIf is designed to execute both the True part and the False part. To verify, copy this into your Debug window and press enter:

 ? IIf(True, MsgBox("True Part"), MsgBox("False Part"))

Obviously, it’s extremely inefficient-and possibly error-inducing-to place functions in the True and False parts of IIf, because they are both executed. In general, always use a standard If…Else…End If block instead.

See also  Does It Make Sense to Splurge on a Laptop?
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist