VBC09350 — Constant expression required
Severity: Error · Family: VBC (static semantics / abstract syntax tree) ·
Source metadata: VBCompileErrorInfo
The value of a constant reads something that has no value until the code runs.
A constant is evaluated once, before the code runs: its value can be made of literals, other constants, members of enumerations and operators, and nothing else - not a variable, nor a call of a function.
MS-VBA reports the same error, with the same message (recorded in Excel).
This code is raised by ConstantExpressionStaticSemantics.
How it is raised
| Situation | Example | Resolution |
|---|---|---|
| A variable. | Const k As Long = n |
Use a variable instead of the constant, or a value made of constants. |
| A function. | Const k = Len("abc") |
Write the value itself: Const k = 3. |
| The constant itself, directly or through other constants - whether or not anything reads it. | Const A = B and Const B = A, Const A = A + 1 |
Give one of them a value that names none of the others. |
Notes
MS-VBAL §5.6.16.1 admits a call of Int, Fix, Abs, Sgn, Len, LenB and of the conversion functions in a constant expression. MS-VBA refuses every one of them, and RD-VBA refuses them as MS-VBA does.
See also
⏮️ VBC09349 Named argument not found | ⏭️ VBC09351 Invalid data type for constant
ACCUEIL • HOME | ℹ️ BIENVENUE • WELCOME | 🧩 BÂTISSONS • BUILD | RD-VBAL | SDK | 🌐 rubberduckvba.ca