RDC11045: Let through a default member with no Property Let
Severity: Warning · Family: RDC (Rubberduck Core analyzers) ·
Raised by: LetToADefaultMemberWithNoPropertyLetAnalyzer
A Let statement assigns a value to a variable of a specific class, or to Me, without naming a member, and the default member of that class has no
Property Let.
MS-VBAL §5.4.3.8
makes the statement valid: the value is let-assigned to the object's default member. MS-VBA refuses it at compile time, with "Invalid use of property" when
the default member is a Property Get and "Type mismatch" when it is a function. RD-VBA compiles it:
| The default member is | When the statement runs |
|---|---|
A Property Get that returns an object |
The value is assigned to that object's default member. |
A Property Get declared another type |
Error 451. |
| A function | Error 438. |
Dim total As New Counter ' Counter's default member: Property Get Value() As Long, no Property Let
total = 5 ' MS-VBA: "Invalid use of property"; RD-VBA: error 451
How it is raised
| Situation | Example | What to do |
|---|---|---|
| The value is meant for the default member. | total = 5 |
Give the class a Property Let for its default member, or assign the member that takes the value by name. |
| The value is meant for a member of the object the default member returns. | sheet = 5, where the default member returns a Range |
Name that member: sheet.Cells(1, 1) = 5. |
| The statement is inside the class. | Me = 5 |
Assign the member by name: Me.Value = 5. |
See also
- RD-VBAL §5.4.3.8 Let Statement
- RDC11046: Let through a Variant property or function
- RD-VBAL §2.6.4 Rubberduck Core Diagnostics
ACCUEIL • HOME | ℹ️ BIENVENUE • WELCOME | 🧩 BÂTISSONS • BUILD | RD-VBAL | SDK | 🌐 rubberduckvba.ca