Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


Late Binding

Posted on 2002-06-19
Medium Priority
Last Modified: 2010-05-02
give me brief intro on late binding
Question by:dipeshpt
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 18

Expert Comment

ID: 7093446
late binding is when you bind an object to a variable at runtime rather than at compile time.


Dim lateBound as Object
set lateBound = CreateObject("Word.Application")

as opposed to:

Dim earlyBound as New Word.Application
LVL 18

Expert Comment

ID: 7093449
btw: if you look it up in msdn, there is a pretty good explanation
LVL 44

Accepted Solution

bruintje earned 200 total points
ID: 7093482
Hi dipeshpt,

this explanation is also very clear

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

LVL 38

Expert Comment

ID: 7093483
Because with late binding every object reference requires extra resolution at runtime (to determine what kind of object it is etc.) it is considerably slower than early binding, where the object reference is compiled with the exe.  Early binding is preferred in all situations unless:

* For some reason you don't want to add a reference to your project (if for example, you are using excel and you want it to work with excel 97 and excel 2000, you would use the late binding technique and you can avoid adding a reference to the excel library in your project.)

* You just don't know what kind of object you will be referencing with the variable.  It is possible to write generic code that handles a wider variety of objects (as long as they share the same methods, properties etc.)

* You are in an environment such as VBScript that doesn't allow variable typing.  You do not have early binding as an option then.
LVL 18

Expert Comment

ID: 7093612
Early binding also gives you the use of the VB IDE's auto-complete feature, which is very handy for developing.  However, because of Paul's first exception above, I often go back and switch all of my Early Binding statements to Late Binding statements after the original development is done.  

One other thing I suspect from my experience, is that you will get more complete resource deallocation using late binding than you will from early binding.  If you do this:

Dim lateBound as Object
set lateBound = CreateObject("Word.Application")

Set lateBound = Nothing

I suspect that you get better resource deallocation than:

Dim earlyBound as New Word.Application
Set earlyBound = Nothing

But I have nothing substantial to base that on.


Expert Comment

ID: 7094834
hi dipeshpt,

There are advantages and disadvantages on using Early or Late Binding. Here let me explain:

-Late Binding:
LateBinding(LB) uses "CreateObject" to create an instance of the application object(like Word, excel etc) which you may want to use in your appliction.
eg: To create an instance of Excel, by using late binding..
Dim objExcel as Object
Set objExce=CreateObject("Excel.Application")

Advantages of late Binding:
1) The main and the MOST important advantage of late binding is that your application is more certain to be 'version dependent'

eg: if you set your reference(ie by early binding) in your application to "Microsoft Word 10.0 Object Library", then the appln will run where the machine has Windows 2000 but cannot run on any lower versions (happened to my application deleivered to my client)
Therefor when you late bind, it will create the object with respect to the available version in that Pc.

2)With numerous references, the file size increases and takes longer to complile.


-Early Binding:
a)First of all you need to set a reference in your project to the application you want to manipulate. This you can do so by going to your Menu in your appln, Project-References and choosing the object you would like to use(ie word or excel or whatever)

b)Then to create a new instance of that referenced application by using Early Binding..
Dim objEcxel as Excel.Application
Set objExcel=New Excel.Application

Advantages of Early Binding:
1)Code runs faster, cos it is compliled upfront with the appliction object(ie the appln knows the object which it is going to use)

2)Debugging is easier
3)Also one can have access ot intellisense ie one can get all the help by pressing F1 plus all the functions, methods and properties are available at design time itself.

I hope this gave you some insight on how both works.



Expert Comment

ID: 7094838
sorry it should be "Version Independent" in advantages of Late Binding-(typo error")

Expert Comment

ID: 7094953
The only thing that determines early or late binding is how you dim your variable

early binding : dim x as Word.Application

Set x = CreateObject("Word.Application")
Set x = New Word.Application

late binding : dim x as Object

you can use
Set x = CreateObject("Word.Application")

If you create your object using the New operator, Visual Basic uses the so-called internal instancing: The object is created internally, without passing through COM. The Instancing property is ignored—otherwise, it wouldn't be possible to instantiate Private objects.

If you create your object using the CreateObject function, the request goes through COM and is subject to the rules enforced by the class's Instancing property, which means that the operation will be successful only if the class is Public and creatable.



Expert Comment

ID: 7230916
LVL 49

Expert Comment

ID: 7923623
Hi dipeshpt,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:

    Accept bruintje's comment(s) as an answer.

dipeshpt, if you think your question was not answered at all or if you need help, just post a new comment here; Community Support will help you.  DO NOT accept this comment as an answer.

EXPERTS: If you disagree with that recommendation, please post an explanatory comment.
DanRollins -- EE database cleanup volunteer

Expert Comment

ID: 7968386
per recommendation

Community Support Moderator @Experts Exchange

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question