VBC00001: Syntax error
Severity: Error · Family: VBC (parser / concrete syntax tree) ·
Source metadata: VBSyntaxErrorInfo
A token was reached that the RD-VBA grammar cannot place in the current context. This is the parser's
general fallback: when the input cannot be parsed and no more specific code applies, it reports
VBC00001. Recurring shapes of syntax error are promoted from VBC00001 to their own code in the
VBC00042–VBC00999 range.
The diagnostic's verbose detail says what MS-VBA says when it compiles the module, and its range is
where MS-VBA puts the caret. In the body of a procedure, that is Syntax error, over the whole line:
from its start (its indentation, label or line number) to its last character, its comment and the
lines it continues on included. In a procedure's header, or in a declaration of the module, it is
Expected: …, at the token where what MS-VBA expected is missing, or right where the line ends.
How it is raised
| Situation | What the verbose detail says | Resolution |
|---|---|---|
A statement in a procedure's body cannot be read, e.g. a misplaced Then, a doubled operator, an unbalanced bracket, an operator with no right operand, a declaration inside a procedure body, or an expression used as a statement. |
Syntax error, over the whole line |
Put the tokens in a legal order, or move or remove the construct. |
A ByVal before an argument of a RaiseEvent (MS-VBAL §5.4.2.20 gives the statement no ByVal, and §5.6.13.1 allows one only in the invocation of an external procedure; for any other call, see VBC09327). |
that a RaiseEvent argument cannot be written with ByVal, at the argument |
Remove the ByVal. |
A procedure's header or a declaration of the module is missing a part, e.g. Sub (), Sub S(x As), Sub S(x, Property X(), Private Type, Declare PtrSafe Sub Foo, Option Compare, Private x As. |
MS-VBA's message: Expected: identifier, Expected: type name, Expected: New or type name, Expected: list separator or ), Expected: expression, Expected: end of statement, Expected: Get or Let or Set, Expected: Lib, or Expected: Text or Binary, at the token MS-VBA puts the caret on. Where the grammar does not tell what was expected, Syntax error, at the token. |
Complete the declaration. |
A conditional-compilation directive line that is not well formed, e.g. #If VBA7 with no Then, #End If junk, #Iff X Then, #Const X As Long = 1. The line is no directive, and opens, continues or ends no block (RD-VBAL §2.6.1). |
MS-VBA's message: Expected: Then, Expected: expression, Expected: end of statement, Expected: =, Expected: identifier, or Expected: If or Else or ElseIf or End or EndIf or Const, at the token MS-VBA puts the caret on |
Complete or correct the directive; write a comment after it with '. |
| A stray or unterminated token, e.g. an unclosed string, an unexpected line continuation, a character outside any token. | in a procedure's body, Syntax error, over the whole line; outside it, what MS-VBA expected there, at the token |
Remove or complete the token. |
| The module is nested more deeply than the parser can read at all: its rules nest more than 32,000 deep, a limit of RD-VBA's parse and not of the language (RD-VBAL §2.6.1). That is an expression or a block nested in thousands of others, such as 32,000 parentheses or 5,300 nested calls, past the 2,500 levels of VBC00060. The parse stops, and nothing of the module is analyzed; a syntax error found before it stopped is reported with it. | This module is nested too deeply to be read, at the start of the module |
Split the deepest part into smaller ones, for example by writing parts of the expression to variables. |
A Tab or Spc clause in a list to print, right before = or &, e.g. Debug.Print Tab(2) = 5, Debug.Print Spc(2) & "x". The clause moves the print position, and is no value to compare or join. MS-VBA refuses these too. A + or a - after a space is no error: it begins the next item. So Debug.Print Tab(2) + 1 prints 1 after the clause, and the VBE writes it Tab(2); 1. |
Syntax error, over the whole line |
To print a value after the clause, write a ; between them: Debug.Print Spc(2); "x". |
Debug is used other than as Debug.Print or Debug.Assert, e.g. Set Debug = Nothing, x = Debug, With Debug, Call Debug.Print("x"). Debug belongs to the host, and is only ever written as those two statements. |
Debug |
Write Debug.Print … or Debug.Assert … as a statement of its own. |
A parameter is named with a reserved word, e.g. Sub S(ByVal Mod As Long), Sub S(ByVal Scale As Long). A reserved word (MS-VBAL §3.3.5.2) cannot name a parameter (MS-VBAL §5.3.1.5), and MS-VBA refuses these too. The rest of the procedure is still analyzed. |
Expected: identifier. 'Mod' is a reserved word and cannot name a parameter., at the name |
Rename the parameter. |
Notes
The RD-VBA grammar is permissive at the token level by design, and defers meaning to the semantic
layers. A VBC00001 is therefore always a structural problem: the text could not be assembled into a
syntax tree at all.
Conditions that need symbol information (an undefined name, a duplicate declaration) are not syntax errors. They are reported later, as semantic compilation errors.
See also
ACCUEIL • HOME | ℹ️ BIENVENUE • WELCOME | 🧩 BÂTISSONS • BUILD | RD-VBAL | SDK | 🌐 rubberduckvba.ca