Table of Contents

VBC09339 — Argument not optional

Severity: Error  ·  Family: VBC (static semantics / abstract syntax tree)  ·  Source metadata: VBCompileErrorInfo

An object is used where a value is expected, and the default member that would give its value takes an argument.

Where a value is expected, an object stands for what its default member returns. A Collection's default member is Item, which takes the key of the item it reads: a Collection has no value of its own to give, and neither has an object of any class whose default member takes an argument that is not Optional.

MS-VBA reports the same error: Argument not optional. The same words are run-time error 449, which a call that leaves out an argument raises.

This code is raised by ObjectValueStaticSemantics, at the object, and by the checks of an assignment's target: a function named as the target of an assignment, or in an Erase statement, is called with no argument, and one that takes an argument is the same error.

How it is raised

Situation Example Resolution
The object is assigned to a variable of a value type. Dim n As Long: n = New Collection Read an item: n = items(1), or n = items.Count.
The object is an operand. s = "Total: " & items The same.
The object is passed to a parameter of a value type, or to a function that reads a value, such as CStr, Abs or Len. Debug.Print CStr(items) The same.
A function that takes an argument is named as the target of an assignment, or in an Erase statement. Left = "x", Set Left = Nothing, Erase Left Assign a variable of your own.

An object passed to a Variant - assigned to one, passed to a ByVal x As Variant parameter, or to a function such as TypeName - is passed as the object it is, and is not this error.

See also


⏮️ VBC09338 Cannot define a Public user-defined type within an object module | ⏭️ VBC09340 Expected Function or variable


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