RDC11021 — Constant of a procedure valued with Len
Severity: Warning · Family: RDC (Rubberduck Core analyzers) ·
Raised by: ProcedureConstantLengthAnalyzer
A Const declared in a procedure is given the length of another constant: Const K3 = Len(K).
The language specification lists Len of a constant among the expressions a constant can be given. MS-VBA disagrees with itself here: it refuses the
same declaration in a module, with Constant expression required, and accepts it in a procedure. In Excel, running the procedure then crashed the host
(recorded in Excel). RD-VBA accepts it in a procedure, as MS-VBA does, gives the constant the length the specification says, and warns: the declaration
cannot be moved to a module, and it is not reliable where it is.
How it is raised
| Situation | Example | Resolution |
|---|---|---|
A Const of a procedure whose value calls Len. |
Const K = "abcd" … Const K3 = Len(K) |
Write the length itself (Const K3 = 4), or compute it in a variable: Dim k3 As Long: k3 = Len(K). |
Notes
A Const of a module valued with Len is VBC09350 Constant expression required, in MS-VBA as in RD-VBA. So is LenB, in a procedure as in
a module. In the bounds of an array, Len and LenB of a constant are valid anywhere (Dim d(Len(K)) As Long), and nothing is reported.
See also
ACCUEIL • HOME | ℹ️ BIENVENUE • WELCOME | 🧩 BÂTISSONS • BUILD | RD-VBAL | SDK | 🌐 rubberduckvba.ca