Table of Contents

RDC11022 — ReDim of a variable declared implicitly

Severity: Warning  ·  Family: RDC (Rubberduck Core analyzers)  ·  Raised by: ReDimOfAnImplicitVariantAnalyzer

A ReDim statement re-dimensions a name the procedure used before it, with no declaration: y = 5, then ReDim y(2).

In a module without Option Explicit, using a name that matches nothing declares it, where it is first used, as a variable of its own: a Variant. The language specification has the ReDim re-dimension that Variant, and VB6 runs it so. MS-VBA disagrees: it refuses the ReDim at compile time, with Invalid ReDim, whether the earlier line writes the name, reads it, or never runs (recorded in Excel). RD-VBA does what the specification says, and warns, because the same module won't compile in MS-VBA.

How it is raised

Situation Example Resolution
A ReDim of a name used earlier in the procedure, with no declaration. y = 5 … ReDim y(2) Declare the variable before its first use: Dim y (a Variant, which holds whatever it's given), or Dim y() As Long if it's only ever an array.

Notes

  • A name used only after its first ReDim is the array that ReDim declares, in MS-VBA as in RD-VBA. That is RDC00114, and nothing is reported here.
  • A ReDim of a declared Variant (Dim y … y = 5 … ReDim y(2)) is valid in MS-VBA too: the Variant becomes an array, whatever it held.

See also


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