Table of Contents

RDC00218: IsMissing of a Variant that is not Optional

Severity: Warning  ·  Family: RDC (Rubberduck Core analyzers)  ·  Raised by: IsMissingOfAVariantThatIsNotOptionalAnalyzer

IsMissing is given a required Variant parameter, or a Variant variable, so it does not tell whether an argument was omitted.

IsMissing returns True when its argument holds the Missing value (MS-VBAL §6.1.2.7.1.6). Only an Optional parameter whose argument was omitted is given that value by the call. A required Variant parameter holds it only when a caller passes on such a parameter of its own, and a Variant variable only when the code assigns one to it. A test of IsMissing of either reads as a check for an omitted argument of the procedure, and it does not tell whether one was omitted.

IsMissing of an Optional Variant parameter with no default value is not reported. IsMissing of a name that can never hold the Missing value is RDC00207.

How it is raised

Situation Example Resolution
A required Variant parameter. Sub Report(Title As Variant) … If IsMissing(Title) Then Declare it Optional (Optional Title As Variant), or remove the test.
A Variant variable. Dim Title As Variant … If IsMissing(Title) Then Test the Optional parameter the value came from.

Quick fix

For a required parameter, the diagnostic comes with a quick fix, Declare the parameter '…' Optional, which lets a call omit it. It writes Optional before the parameter (Optional ByVal Title As Variant). A call that passes the argument does the same as before, and a call may then omit it.

The quick fix is offered for a Sub or a Function whose later parameters are all Optional and which has no ParamArray (MS-VBAL §5.3.1.5 Parameter Lists). It is not offered for:

  • a property, whose accessors declare the same parameters;
  • an event handler or an interface implementation, declared as the event or the interface says;
  • a Public member of a class module, which a class that Implements it declares with the same parameters.

See also


ACCUEIL • HOME | ℹ️ BIENVENUE • WELCOME | 🧩 BÂTISSONS • BUILD | RD-VBAL | SDK | 🌐 rubberduckvba.ca