VBC09306 — Invalid ReDim
Severity: Error · Family: VBC (static semantics / abstract syntax tree) ·
Source metadata: VBCompileErrorInfo
A ReDim statement re-dimensions a member of an object declared As Object.
A ReDim re-dimensions a variable of the code's own. A member of an object is reached through the object, and the array it is, if it is one, belongs to the object's class, which is what re-dimensions it. MS-VBA refuses it at compile time, with this message for an object that is late bound (As Object), and with VBC09316 Method or data member not found for one whose class is declared.
MS-VBA reports the same error: Invalid ReDim.
This code is raised by StatementStaticSemanticsEvaluator, at the target of the statement.
How it is raised
| Situation | Example | Resolution |
|---|---|---|
A member of an Object. |
Dim o As Object … ReDim o.Items(1 To 3) |
Give the class a procedure that re-dimensions its own array, and call it. |
The member of a With block's Object. |
With o … ReDim .Items(1 To 3) |
The same. |
Notes
What MS-VBA does, recorded in Excel; MS-VBAL §5.4.3.3 only says that the target of a ReDim is a variable.
- A member of a
Variantis not known to be an object's until the code runs, and compiles: the member is read as a value, and that value is what is re-dimensioned - the member is as it was afterwards. AVariantthat holds no object raises error 424, Object required. - A field of a record (
ReDim r.Items(3),With r…ReDim .Items(3)), and a variable of a module named through it (ReDim Module1.Items(3)), are variables, and are re-dimensioned.
🧩 Nothing in the runtime prevents re-dimensioning an object's array through the object: it could write the array back through the member, as an assignment does. RD-VBA does what MS-VBA does, so that the code means what it means in MS-VBA and a compile error is where it is expected; a language-level extension could allow it in the future, as a dialect of its own.
See also
⏮️ VBC09305 Invalid ParamArray use | ⏭️ VBC09307 Expected array
ACCUEIL • HOME | ℹ️ BIENVENUE • WELCOME | 🧩 BÂTISSONS • BUILD | RD-VBAL | SDK | 🌐 rubberduckvba.ca