Table of Contents

VBC00060: Expression nested too deeply

Severity: Error  ·  Family: VBC (parser / concrete syntax tree)  ·  Source metadata: VBSyntaxErrorInfo

An expression is nested in more than 2,500 other expressions.

An expression is nested in another when it is part of it: the operand of an operator, an expression in parentheses, the argument of a call. In x = (((1))), the 1 is nested in three expressions. In x = 1 + 2 + 3, the 1 is nested in two additions, because 1 + 2 is the left operand of (1 + 2) + 3. A chain of 2,501 terms joined by + is as deep as RD-VBA reads: its first term is nested in 2,500 additions.

An expression is also nested in what is written around it to use it: the . or ! after it (a.b), the parentheses of an index or a call it is the target of (a(1)), and New, TypeOf … Is and AddressOf. A fluent chain costs two levels a link: in b.Add(1).Add(2), b is nested in four expressions, and a chain of 1,251 links is too deep. The arguments of a call statement are nested in the call, written with Call or without it.

Passing an argument by name (a:=) or ByVal nests it in nothing more than the call. Neither does printing it: Debug.Print, Spc and Tab are not calls, and what they print is as deep as it is in x =.

MS-VBA reports no error for an expression this deep. Excel runs a chain of 2,500 terms, 2,000 nested parentheses and 1,000 nested calls. Given a chain of 3,000 terms, it stops responding and closes, with no dialog (recorded in Excel). RD-VBA reports this error instead, at the expression that passes the limit.

The expression of a directive (#If, #ElseIf, #Const) has the same limit, but its parentheses are not counted: #If ((x)) Then is as deep as #If x Then, however many parentheses there are. An operator, a call and a negation count as they do in a statement. A condition past the limit has no value, and neither has a #Const set to an expression past the limit: no branch of an #If it decides is marked as excluded.

This code is raised by the parser, once for each expression of a statement or directive that passes the limit. What is nested past the limit is kept as it is written, but is not analyzed: a name in it is not found by Go to Definition or Find All References, and has no hover. Find All References says that what it found may be incomplete when a name there could be the one you asked about, and renaming that variable or procedure is refused, since the name there would be left as it was. A variable used only there can be reported as unused. While a module has this error, no code in its project runs: a run reports this error instead.

How it is raised

Situation Example Resolution
A long chain of operators. total = a1 + a2 + a3 + ... + a2600 Add the terms a few hundred at a time, into a variable.
Deeply nested parentheses or calls. x = Abs(Abs(Abs( ... Abs(n) ... ))), 2,600 deep Compute the inner part first, and assign it to a variable.
A long fluent chain of calls. Set q = b.Add(1).Add(2).Add(3) ... .Add(1300) Break the chain: assign what part of it returns to a variable, and go on from it.

Code generated by a tool is the usual source of an expression this deep. Writing part of it to a variable first gives the same result, and the code runs in MS-VBA too.

See also


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