PRB: Non-Reserved Word w/ Colon Behaves Differently in VB 4.0

Last reviewed: October 30, 1995
Article ID: Q129935
The information in this article applies to:
  • Standard, Professional, and Enterprise Editions of Microsoft Visual Basic, 16-bit and 32-bit, for Windows, version 4.0

SYMPTOMS

Using Non-reserved keywords followed by a colon may produce different results in Visual Basic version 4.0.

A reserved keyword in Visual Basic cannot be used as the name of a user-defined function. However, a non-reserved keyword may be used as the name of a user-defined function.

In Visual Basic version 4.0 a non-reserved word followed by a colon is interpreted as a line label. Previous versions of Visual Basic checked to see if this is a statement followed by another statement on the same line.

Similar behavior occurs when you use a user-defined subroutine with no parameters followed by a colon and another statement.

RESOLUTION

To avoid the confusion that this could potentially cause, Microsoft recommends that you use colons only for line labels. Write each individual statement on a separate line. Not only does this allow you to avoid confusion, it also makes your code easier to read.

STATUS

This behavior is by design.

MORE INFORMATION

Steps to Reproduce Behavior

  1. Start a new project in Visual Basic. Form1 is created by default.

  2. Place a command button (Command1) on the form.

  3. Place the following code inside the Command1 click event:

    Print "Hello" Cls: Beep

  4. Run the program by choosing Start from the Run menu.

  5. Click the Command1 button.

In Visual Basic version 4.0, the word Hello is printed on the form and a beep sounds. In previous Visual Basic versions, Hello is printed, and then erased; then the beep sounds.


Additional reference words: 4.00 vb4win vb4all
KBCategory: kbprg kbprb
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: October 30, 1995
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.