Table of Contents

RDC00202: Module-scope Dim declaration

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

A module-level variable is declared with Dim.

At the module level Dim declares a Private variable, the same as Private does (MS-VBAL §5.2.3 Module Declarations); Dim is the keyword of a local variable, and Private and Public state what a module-level one is. The diagnostic is an opinion of the analyzer and not a condition of the language: both are legal VBA.

That a statement is written with Dim is a fact of the way it is written: the analyzer reads it off the syntax tree, and makes one finding for each statement, however many variables it declares. It is a suggestion because Private does not change what the variable is.

How it is raised

Situation Example Resolution
A variable is declared with Dim outside of any procedure. Dim total As Long Write Private, or Public if the variable is meant to be accessible from other modules.
A Dim statement outside of any procedure declares several names. Dim first, last As String Write each name in a Private statement of its own, with its own type: Private first and Private last As String.

A Dim statement of several names is reported here and not as RDC00204: its one keyword declares every variable of the list (MS-VBAL §5.2.3.1 Module Variable Declaration Lists).

Quick fix

The diagnostic comes with a quick fix, Write Private in place of Dim. It writes Private in place of Dim, and the variable is what it was. For a statement of several names it also declares each name on a line of its own, with the type it has: Dim a, b As Long becomes Private a and Private b As Long, and a stays a Variant. It is not offered for a statement of several names that declares a WithEvents variable, which is not split; a statement of one WithEvents variable is written Private.

See also


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