Table of Contents

RDC01017: Write-only property

Severity: Information  ·  Family: RDC (Rubberduck Core analyzers)  ·  Raised by: WriteOnlyPropertyAnalyzer

A public property has a Property Let or a Property Set, and no Property Get.

Code that uses the module can assign the property and never read it (RD-VBAL §5.3.1.7 Property Declarations). A value that can be set and never read back is rarely what is meant, and a Sub says what such a property does more plainly.

A property with both a Let and a Set is reported once, at the first of them. A Private or Friend property is not reported.

The finding is the name of the property.

How it is raised

Situation Example Resolution
A public Property Let or Property Set with no Property Get. Public Property Let Size(ByVal value As Long)
End Property
Add a Property Get, or write a Sub that says what it does (SetSize).

Quick fix

A Property Let with one parameter comes with a quick fix, Add a Property Get '…' that returns the value the Let keeps in '…'. It declares a Private variable of the module (mSize), makes the Let assign it its value first, and adds a Property Get that returns it. What the Let did before, it still does.

It is not offered for a class that another module implements (Implements): the Get would be a member of the interface that the implementing modules lack. Nor is it offered for a property with a Property Set, whose variable would keep the object alive after the code that uses it releases it.

See also


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