Scope of Line Labels/Numbers in Visual Basic for Windows

Last reviewed: June 21, 1995
Article ID: Q78335
The information in this article applies to:

- Standard and Professional Editions of Microsoft Visual Basic for

  Windows, versions 2.0 and 3.0
- Microsoft Visual Basic programming system for Windows, version 1.0

SUMMARY

Line labels (and line numbers) do not follow the same scoping rules as variables and constants in Visual Basic for Windows. Line labels must be unique within each module and form. However, you can only transfer control to a line label or line number within the current Sub or Function.

MORE INFORMATION

When you attempt to define the same line label twice within a module or form, you receive the error message "Duplicate label". This message means that the label is already defined in another procedure within the current module.

When you use a GOTO or GOSUB statement that names a line label defined in another procedure, you receive the error message "Label not defined." This message means that the label is not defined in the current Sub or Function.

For more information about line labels, see the description of the GOTO and GOSUB statements in the "Microsoft Visual Basic: Language Reference" or in the Visual Basic for Windows online Help system.


Additional reference words: 1.00 2.00 3.00
KBCategory: kbprg kbcode
KBSubcategory: PrgCtrlsStd


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: June 21, 1995
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.