RDC00215: Self-assigned declaration
Severity: Hint · Family: RDC (Rubberduck Core analyzers) ·
Raised by: SelfAssignedDeclarationAnalyzer
A variable is declared As New.
Such a variable creates its own object (MS-VBAL §2.5.1 Automatic Object Instantiation). The object is
created the first time the variable is used, not where it is declared. Once the variable is set to Nothing, the next use creates a new object, so
x Is Nothing is never True. Code that expects the object to be gone, or to be the same one, does not see what it expects.
The finding is the name of the variable.
How it is raised
| Situation | Example | Resolution |
|---|---|---|
A variable declared As New. |
Dim items As New Collection |
Declare it As Collection, and create the object where it is needed: Set items = New Collection. |
See also
ACCUEIL • HOME | ℹ️ BIENVENUE • WELCOME | 🧩 BÂTISSONS • BUILD | RD-VBAL | SDK | 🌐 rubberduckvba.ca