VBC09340 — Expected Function or variable
Severity: Error · Family: VBC (static semantics / abstract syntax tree) ·
Source metadata: VBCompileErrorInfo
A subroutine is used where a value is expected.
A Sub does something and returns nothing: it can be called, but it has no value to print, to assign, or to give to an operator or to another procedure.
MS-VBA reports the same error, with the same message (recorded in Excel).
This code is raised by ObjectValueStaticSemantics, and by
StatementStaticSemanticsEvaluator for the target of an assignment.
How it is raised
| Situation | Example | Resolution |
|---|---|---|
A Sub printed or assigned. |
x = Module1.Reset |
Make it a Function that returns a value, or call it on a line of its own. |
A Sub used as an operand. |
x = c.Increment + 1 |
Call the Sub first, then read the value it changed. |
A Sub of an object, or of a module named through it, assigned to. |
c.Remove(1) = 5, Err.Clear = 1 |
Call the Sub, then assign what you meant to assign. |
See also
⏮️ VBC09339 Argument not optional | ⏭️ VBC09341 Can't assign to read-only property
ACCUEIL • HOME | ℹ️ BIENVENUE • WELCOME | 🧩 BÂTISSONS • BUILD | RD-VBAL | SDK | 🌐 rubberduckvba.ca