RDC01004: Empty code block
Severity: Information · Family: RDC (Rubberduck Core analyzers) ·
Raised by: EmptyCodeBlockAnalyzer
An Else, Case, Do, For, For Each or While block has no statement.
Comments, line labels and Dim, Static and Const declarations are no statements: a block that holds only those is empty. An empty block is often unfinished code.
- An empty
Elsedoes nothing, and can be removed. - An empty
Casedoes nothing for its values, and keeps them from theCaseclauses after it: aCasedoes not fall through to the next one (MS-VBAL §5.4.2.10 Select Case Statement). - An empty loop still evaluates its condition, its bounds or its collection, and a
Forloop leaves its counter past the end (MS-VBAL §5.4.2.3 For Statement).
An empty Case Else is not reported: it states that the other values are left alone. An empty If or ElseIf branch is RDC01003.
The finding is the header of the block, its keyword and what it states.
How it is raised
| Situation | Example | Resolution |
|---|---|---|
An Else with no statement. |
If foo Then DoSomethingElseEnd If |
Remove the Else. |
A Case with no statement. |
Case 0Case Is > 0 Debug.Print foo |
Write what it does. A Case meant to do nothing for its values can say why in a comment; the finding remains. |
A Do loop with no statement. |
DoLoop While foo < 100 |
Remove the loop, or write its body. |
A For or For Each loop with no statement. |
For i = 0 To fooNext |
Remove the loop, or write its body. Assign the counter if its last value is what the loop is for. |
A While loop with no statement. |
While foo < 100Wend |
Remove the loop, or write its body. |
Quick fix
An empty Else comes with a quick fix, Remove the empty Else. It removes the lines from the Else to the End If, and the program does the same. It is
offered when nothing at all is written in the Else: no comment, line label, declaration or #If directive, and no other statement on its line.
The other blocks have no quick fix: removing an empty loop or Case can change what the program does.
See also
- RD-VBAL §2.6.4 Rubberduck Core Diagnostics
- RD-VBAL §5.4.2.4 For Each Statement
- RD-VBAL §5.4.2.6 Do Statement
ACCUEIL • HOME | ℹ️ BIENVENUE • WELCOME | 🧩 BÂTISSONS • BUILD | RD-VBAL | SDK | 🌐 rubberduckvba.ca