Table of Contents

RDC11043: Object assigned with Let to a Variant property

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

A Let assignment gives an object to a property whose value parameter is a Variant.

RD-VBA passes the property the object itself, as MS-VBA does. What happens to the object is up to the property: a Property Let of a class receives the object, and a library object's property may read its default member, or raise an error. MS-VBAL §5.4.3.8 evaluates the value as a simple data value instead: the property receives the value of the object's default member.

Dim b As New Box          ' Property Let Item(ByVal v As Variant)
Dim r As Object
Set r = New Collection
b.Item = r                ' b receives the Collection itself

The warning is raised where the value is declared as an object (a class, or Object) and the property is bound early. A Variant that holds an object at run time, and a property called late, are not reported.

How it is raised

Situation Example Resolution
The property is meant to receive the default member's value. b.Item = r where r has a default member Name the default member: b.Item = r.Value.
The property is meant to receive the object. b.Item = r Make it explicit: declare a Property Set and assign with Set b.Item = r.

See also


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