VBC09371 — Array argument must be ByRef
Severity: Error · Family: VBC (static semantics / abstract syntax tree) ·
Source metadata: VBCompileErrorInfo
An array parameter is declared ByVal, or an argument of one is written ByVal.
An array parameter (a() As Long) is always ByRef: the procedure is given the array itself, never a copy of it, so an array cannot be passed by value.
ByVal written in its declaration, or before its argument, asks for what the parameter cannot be.
MS-VBA reports the same error, with the same message (recorded in Excel).
This code is raised where the declarations of a module are checked, at the parameter declared ByVal, and where a call is checked, at the argument
written ByVal.
How it is raised
| Situation | Example | Resolution |
|---|---|---|
An array parameter declared ByVal: of a procedure, a property, an event, a Declare, or an implementation of an interface's member. |
Sub Bump(ByVal a() As Long) |
Remove ByVal: Sub Bump(a() As Long). To work on a copy, copy the array in the procedure. |
An array given ByVal to an array parameter. |
Sub Bump(a() As Long) … Bump ByVal values |
Remove ByVal: the procedure works on the array. To work on a copy, copy it first: Dim copy() As Long: copy = values. |
See also
⏮️ VBC09370 Expected procedure, not variable | ⏭️ VBC09372 Member already exists in an object module from which this object module derives
ACCUEIL • HOME | ℹ️ BIENVENUE • WELCOME | 🧩 BÂTISSONS • BUILD | RD-VBAL | SDK | 🌐 rubberduckvba.ca