RDC01011: Variable not used
Severity: Information · Family: RDC (Rubberduck Core analyzers) ·
Raised by: VariableNotUsedAnalyzer
Nothing reads the value of a variable: nothing refers to it, or only its assignments do.
A variable that is never read does nothing for the program. It is often left over from code that changed, or a name typed where another was meant. When it is assigned, the message says so: the value assigned to it is lost.
Only the variables that nothing outside the module can refer to are counted: a local variable, and a Private variable of the module (Dim or Private).
A Public or Friend variable may be read by another module, or by code that uses the class. A WithEvents variable is used by the events it handles, and
the control variable of a For or For Each loop by the loop: neither is reported.
The finding is the name of the variable.
How it is raised
| Situation | Example | Resolution |
|---|---|---|
| A variable nothing refers to. | Dim unused As Long |
Remove it. |
| A variable that is assigned and never read. | Dim total As Longtotal = 42 |
Remove it and its assignments, or use its value where it was meant to be used. |
Quick fix
A variable nothing refers to comes with a quick fix, Remove the declaration of 'unused'. It removes the lines of the declaration, and the program does the
same. It is offered when the statement declares no other name and nothing else is written on its lines (no comment, label or other statement), and when no
ReDim names the variable: without the declaration, the ReDim would declare an array of its own. A variable that is assigned has no quick fix, because its
assignments would remain.
See also
ACCUEIL • HOME | ℹ️ BIENVENUE • WELCOME | 🧩 BÂTISSONS • BUILD | RD-VBAL | SDK | 🌐 rubberduckvba.ca