Table of Contents

RDC11012 — Set of a call that always fails

Severity: Error  ·  Family: RDC (Rubberduck Core analyzers)  ·  Raised by: SetThroughACallAnalyzer

A Set statement assigns to a function, or to a property that has no Property Set, and the statement raises a run-time error every time it runs.

Named as the target of a Set, a function or a property with no Property Set is called, and what it returns is Set through its default member. That works only when it returns an object whose default member has a Property Set itself. When the function is declared as a class whose default member has none (a Collection, whose default member Item cannot be Set), there is nothing to Set, and the statement raises run-time error 438 (Object doesn't support this property or method) whenever it runs.

MS-VBA compiles it all the same, and says nothing until it runs (recorded in Excel). RD-VBA reports it as soon as it is written, as the error it is.

How it is raised

Situation Example Resolution
A function declared as a class whose default member has no Property Set, as the target of a Set outside its own body. Function Items() As Collection … Set Items = New Collection Set a variable instead (Set mItems = New Collection), or give the function's module a property with a Property Set to assign through.

Notes

A function of a class whose default member has a Property Set is not reported: Set One = New Settable, where One returns an object whose default member can be Set, sets that member, in MS-VBA as in RD-VBA.

A function or a property declared As Object or As Variant is not reported either: whether the Set works depends on what it returns when it runs. It raises error 424 (Object required) when what it returns is no object. A function of another type than an object, named as the target of a Set, is a compile error already (VBC09345 Invalid use of property).

See also


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