Table of Contents

RDC00310: Redundant ByVal argument

Severity: Hint  ·  Family: RDC (Rubberduck Core analyzers)  ·  Raised by: RedundantByValArgumentAnalyzer

An argument is written ByVal for a parameter that is ByVal already.

The parameter takes its argument by value whether ByVal is written before it or not: Twice(ByVal 2) and Twice(2) pass the same value the same way. An object is passed as itself, not as the value of its default member, which a pair of parentheses would make it. The keyword changes nothing.

MS-VBA compiles it. MS-VBAL §5.6.13.1 says ByVal is written only before an argument of an external procedure, and RD-VBA compiles it where MS-VBA does (RD-VBAL §5.6.13.1 Argument Lists). Written anywhere else, ByVal is a compile error, the one MS-VBA reports: Type mismatch before an argument of a ByRef parameter, and a Syntax error before one of a function MS-VBA compiles inline, such as Len or InStr.

ByVal is not redundant before an argument of a Declare's ByRef or As Any parameter, or of VarPtr: there it passes a value where an address goes.

How the parameter is declared is a fact of the argument (ArgumentFact), which the environment host found.

How it is raised

Situation Example Resolution
An argument of a ByVal parameter of the workspace, of a library, of a class, or of a Declare. Twice(ByVal 2), Left("abc", ByVal 1), k.Add ByVal n Remove ByVal: Twice(2).
The same, given by name. Twice(n:=ByVal 2) Remove ByVal: Twice(n:=2).

See also


ACCUEIL • HOME | ℹ️ BIENVENUE • WELCOME | 🧩 BÂTISSONS • BUILD | RD-VBAL | SDK | 🌐 rubberduckvba.ca