VBC09369 — Can't change data types of array elements
Severity: Error · Family: VBC (static semantics / abstract syntax tree) ·
Source metadata: VBCompileErrorInfo
A ReDim statement gives an array elements of another type than the one the array is declared with.
A ReDim changes an array's dimensions. Its As clause, when it has one, repeats the element type: New is part of it, so an array declared As New is
redimensioned As New too.
MS-VBA reports the same error, with the same message (recorded in Excel).
This code is raised where the statements of a procedure are checked, at the ReDim statement.
How it is raised
| Situation | Example | Resolution |
|---|---|---|
The As clause names another type. |
Dim a() As Long … ReDim a(10) As String |
Write the type the array is declared with, or leave the As clause out. |
The As clause adds New, or leaves it out. |
Dim a() As Collection … ReDim a(10) As New Collection |
Declare the array As New Collection to begin with, or leave the As clause out. |
See also
⏮️ VBC09368 Invalid use of New keyword | ⏭️ VBC09370 Expected procedure, not variable
ACCUEIL • HOME | ℹ️ BIENVENUE • WELCOME | 🧩 BÂTISSONS • BUILD | RD-VBAL | SDK | 🌐 rubberduckvba.ca