VBC09362: Type mismatch: array or user-defined type expected
Severity: Error · Family: VBC (static semantics / abstract syntax tree) ·
Source metadata: VBCompileErrorInfo
A parameter declared as an array is given something that is not an array of its element type.
A parameter declared as an array (A() As Long) is another name for the array passed to it. An array of another element type cannot be it, and neither can
a Variant, even one that holds an array of the right type.
MS-VBA reports the same error, with the same message (recorded in Excel, oracle\s57 A05, s58 G01-G12, s59 G13-G20, s61 G21-G34).
This code is raised by ArgumentListStaticSemantics, where the arguments of a call are matched to its parameters, the standard library's (IRR) among them.
It does not check a ParamArray or the parameters of a Declared procedure.
How it is raised
| Situation | Example | Resolution |
|---|---|---|
An array of another element type: an Enum is not a Long here, nor a String * N a String. Any two Enum types are the same element type. |
Dim a(2) As Integer … TakesLongArray a |
Declare the array with the parameter's element type. |
A member of a late-bound object, which is a Variant. |
Dim o As Object … TakesLongArray o.Values |
Declare the object as its class. |
A Variant that holds an array, or what Array or Split returns. |
Dim v As Variant: v = a … TakesLongArray v; TakesStringArray Split(s) |
Pass the array variable itself, or declare the parameter As Variant. |
| A scalar. | Dim n As Long … TakesLongArray n |
Pass an array. |
| An array in parentheses, which is a value. | TakesLongArray (a); Count((a)) |
Remove the parentheses. |
See also
- RD-VBAL §5.3.1.11 Procedure Invocation Argument Processing
- RD-VBAL §2.6.2 Semantic Compilation Errors
ACCUEIL • HOME | ℹ️ BIENVENUE • WELCOME | 🧩 BÂTISSONS • BUILD | RD-VBAL | SDK | 🌐 rubberduckvba.ca