ID: Q147663
The information in this article applies to:
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.
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.
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 : kbprg kbVBp400 EnvtDes VB4WIN vbwin
Version : WINDOWS:4.0
Platform : NT WINDOWS
Issue type : kbinfo
Last Reviewed: October 2, 1997