Table of Contents

RDC00207 — IsMissing that is always False

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

IsMissing is given a parameter that can never be missing, so it always returns False.

IsMissing tells whether an Optional argument was left out of a call (MS-VBAL §6.1.2.7.1.6). It can only tell for a Variant parameter: an argument left out of a call leaves a parameter of any other type the default value of its type - 0, an empty string, Nothing - which is a value like any other, and gives an Optional Variant its default value when it has one. Code that tests IsMissing of such a parameter looks like it handles the argument being left out, and never does. MS-VBA compiles it without a word.

A Variant parameter with no default value can be missing, whether it is Optional or not (an argument that was left out, passed on to it), and so can a ParamArray that was given no arguments: neither is reported. The fact is the environment host's, from the declaration of the parameter (ValueExpressionSemanticFlags.IsMissingAlwaysFalse).

How it is raised

Situation Example Resolution
The parameter is not a Variant. Sub Report(Optional Copies As Long) … If IsMissing(Copies) Then Give it a default value and test for that (Optional Copies As Long = 1), or declare it As Variant.
The parameter is an Optional Variant with a default value. Sub Report(Optional Title As Variant = "") … If IsMissing(Title) Then Test for the default value, or remove it so that IsMissing can tell.

The results are MS-VBA's, recorded in Excel: IsMissing of an Optional n As Long, an Optional s As String, an Optional o As Object and an Optional v As Variant = 5 is False when the argument is left out; of an Optional v As Variant, and of a ParamArray given nothing, it is True.

See also


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