IsMissing Function

Named Arguments

Syntax

IsMissing( argname) argname

Use: Required

Data Type: Variant

The name of an optional procedure argument of type Variant.

Return Value

Boolean (True or False).

Description

Determines whether an argument has been passed to a procedure.

Rules at a Glance

• If the argument name passed to IsMissing has not been passed to the procedure, True is returned; otherwise, IsMissing returns False.

• False is returned if IsMissing is used on data types other than variants, which may lead to incorrect handling of optional arguments.

Programming Tips & Gotchas

• Always use IsMissing to detect a missing optional variant parameter.

• Version 5 of both VB and VBA for the first time allowed other data types to be used as optional arguments within procedure prototypes; previously, optional arguments had to be variants. However, if you use data types other than variants for optional arguments, you can't use the IsMissing function; instead, you must check for the uninitialized value of the data type. For example, if an integer argument is missing, its value is 0. This can cause confusion, because you have no way of knowing whether a 0 was a legal value passed to the procedure or whether the argument was not passed at all. The only safe way to use optional arguments is to continue to use variants and to check their validity using the IsMissing function.

• You can't use IsMissing on an optional ParamArray because the function always returns False. Instead, you should check for a missing or empty ParamArray by using UBound and LBound to compare the values of its upper and lower bounds; if the ParamArray is empty, the upper bound is less than the lower bound.

See Also

LBound Function, UBound Function

IsMissing Function 393

+2 0

Post a comment