VBC09327 — ByVal argument not allowed here
Severity: Error · Family: VBC (static semantics / abstract syntax tree) ·
Source metadata: VBCompileErrorInfo
An argument is written with the ByVal keyword in an argument list that is not that of an invocation of an external
procedure.
MS-VBAL §5.6.13.1 Argument Lists
gives argument-expression = ["byval"] expression, and says the keyword flags that argument as a ByVal argument. It is
invalid for an argument list to contain one unless it is the argument list for an invocation of an external procedure: a
procedure declared with Declare.
This code is raised by
ExpressionStaticSemanticsEvaluator, where
the callee is known: the parser cannot tell what is being invoked, so it keeps the keyword in the tree
(ByValArgumentExpressionNode) and leaves the
rest to the rule about calls.
How it is raised
| Situation | Example | Resolution |
|---|---|---|
A procedure of the workspace is called with a ByVal argument. |
Foo ByVal x, for a Sub Foo(ByRef n As Long) |
Declare the parameter ByVal, which is how a procedure says it takes its argument by value. Or pass a copy: Foo (x). |
A ByVal argument is named. |
Foo n:=ByVal x |
As above. |
| The thing called is not a procedure. | arr(ByVal i) |
Remove the keyword. |
Notes
A ByVal argument of an external procedure is valid whatever its parameter was declared as, and is passed by value.
RaiseEvent is never the invocation of an external procedure, and has no ByVal in its grammar at all
(MS-VBAL §5.4.2.20): there the keyword is a syntax error (VBC00001), reported by the parser.
See also
- VBC00001 — syntax error, which a
ByValbefore aRaiseEventargument is - RD-VBAL §2.6.2 Semantic Compilation Errors
- RD-VBAL §5.6.13.1 Argument Lists
⏮️ VBC09326 Invalid event handler | ⏭️ VBC09328 Invalid Implements directive
ACCUEIL • HOME | ℹ️ BIENVENUE • WELCOME | 🧩 BÂTISSONS • BUILD | RD-VBAL | SDK | 🌐 rubberduckvba.ca