INFO: Multiple vbCancel Constants Defined with VB 4.0

Last reviewed: September 30, 1997
Article ID: Q147663
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

SUMMARY

Both the Visual Basic and the Visual Basic For Applications type libraries define a constant called vbCancel. The value for this constant is different in each type library.

MORE INFORMATION

The value for the vbCancel constant defined in the "Visual Basic For Applications" type library is 2. The value defined in the "Visual Basic objects and procedures" type library is 0. The value that will be returned if vbCancel is used in code without a type library prefix is 2, because the VBA type library appears first in the list of references displayed in the References dialog.

This can be an issue when the vbCancel constant is expected to return 0. For example, the Drag method can take a parameter named Action. To cancel a drag operation, the documentation instructs setting the Action parameter to vbCancel, where vbCancel is 0. Unfortunately, because the VBA type library exists before the Visual Basic type library, a value of 2 will be used instead of a value of 0. A value of 2 in the context of the Drag method indicates that the drag operation on the specified object is complete. If the string VB.vbCancel is used, the correct value of 0 will be substituted and the code will work properly.

Steps To Reproduce

  1. Start Visual Basic 4.0. Form1 is created by default.

  2. Press the F5 key or select Start from the Run menu to start the default application.

  3. Press CTRL+BREAK, or select Break from the Run menu to pause the application.

  4. In the debug window, enter these lines of code and observe the results:

          Print VBA.vbCancel
          Print VB.vbCancel
    

The first line of code returns 2. The second returns 0.
Keywords          : EnvtDes VB4ALL VB4WIN vbwin GnrlVb kbprg
Technology        : kbvba
Version           : WINDOWS:4.0
Platform          : NT WINDOWS
Issue type        : kbinfo


================================================================================


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: September 30, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.