Table of Contents

VBC09309 — Label not defined

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

A statement names a line label or a line number as its jump target, but the procedure that contains the statement does not define it. A procedure that jumps to a label must contain exactly one definition of that label.

A label belongs to its procedure, not to the block it is written in, and it is never a variable: the target is looked up among the labels the procedure defines, not among the symbols in scope.

See RD-VBAL §2.6.2 Semantic Compilation Errors and MS-VBAL §5.4.2.12 GoTo Statement–MS-VBAL §5.4.2.16 On...GoSub Statement, MS-VBAL §5.4.4.1 On Error Statement, MS-VBAL §5.4.4.2 Resume Statement.

The verbose detail names the label that was not found.

How it is raised

Situation Example Resolution
A GoTo or GoSub names a label the procedure does not define. GoTo Done with no Done: line Define the label in the same procedure, or correct its spelling. Label names are not case-sensitive.
One label in an On … GoTo / On … GoSub list is not defined. On n GoTo A, Missing Define every label in the list. Each undefined label is reported on its own.
On Error GoTo names a handler label that is not defined. On Error GoTo Handler with no Handler: Define the handler label in the procedure.
Resume names a label that is not defined. Resume Retry with no Retry: Define the label, or use Resume Next to continue after the statement that failed.
A line number that nothing defines. GoTo 200 when only 100: exists Define the line number label, or jump to one that exists.

Notes

On Error GoTo 0 and On Error GoTo -1 do not refer to a label: 0 turns error handling off and -1 clears the active error. Neither is ever looked up, so this code is not raised for them, whether or not the procedure defines a line 0.

Resume 0 is likewise not a jump. Any other number is a line number label and must be defined.

A label defined inside a nested block (If, Do, For, Select Case, With) is defined for the whole procedure, so a jump from outside the block to it is not reported here. A label that is defined more than once is a different condition (VBC09319) and is not reported by this code.

See also


⏮️ VBC00042 Numeric literal overflow | ⏭️ VBC09312 Exit Do not within Do...Loop


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