PRB: Variable Not Defined Error Message When Using a Constant

Last reviewed: January 8, 1998
Article ID: Q179027
The information in this article applies to:
  • Microsoft Visual Basic Learning, Professional, and Enterprise Editions for Windows, version 5.0
  • Microsoft Visual Basic Standard, Professional, and Enterprise Editions, 16-bit and 32-bit, for Windows, version 4.0

SYMPTOMS

The following error message displays when you attempt to use a predefined constant for an automation server:

   "Compile Error:
   Variable Not Defined"

For example, you may receive this error when you try to use the constant xlR1C1 from the Microsoft Excel Object Library.

CAUSE

You are using late binding on an ActiveX component.

RESOLUTION

You can use early binding by referencing the object library for the automation server in your project. Click References on the Project menu to select the object library.

  • or-

If you want to use late binding, declare your own constant and assign it to the numeric value of the predefined constant. For example, the constant xlR1C1 is equivalent to -4150. Therefore, you could add the following to your project.

      Const xlR1C1 = -4150

STATUS

This behavior is by design.

MORE INFORMATION

Late Binding occurs when you declare a variable As Object, As Form, As Control, or As Variant and Visual Basic cannot determine at compile-time what sort of object reference the variable will contain. Therefore, Visual Basic must use late binding to determine at run-time whether the actual object has the properties and methods you call using the variable.

Early Binding occurs when you make a reference to the object library at design-time. Visual Basic then knows what object library contains the properties and methods when you make your variable call. Early Binding also provides some performance gains.

REFERENCES

"How Binding Affects ActiveX Component Performance" in the Visual Basic Component Tools Guide, version 5.0.

Keywords          : VB4ALL VB4WIN vb5all VBKBAX_VBKBComp kberrmsg
Version           : WINDOWS:4.0,5.0
Platform          : WINDOWS
Issue type        : kbprb


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


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