?
Solved

Late Binding

Posted on 2002-06-19
11
Medium Priority
?
555 Views
Last Modified: 2010-05-02
give me brief intro on late binding
0
Comment
Question by:dipeshpt
[X]
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
11 Comments
 
LVL 18

Expert Comment

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

ie:

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

as opposed to:

Dim earlyBound as New Word.Application
0
 
LVL 18

Expert Comment

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

Accepted Solution

by:
bruintje earned 200 total points
ID: 7093482
Hi dipeshpt,

this explanation is also very clear
http://edocs.bea.com/wls/docs70/jcom/overview.html#1107478

HAGD:O)Bruintje
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 38

Expert Comment

by:PaulHews
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.
0
 
LVL 18

Expert Comment

by:mdougan
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.

0
 
LVL 2

Expert Comment

by:priya_pbk
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.

-priya


0
 
LVL 2

Expert Comment

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

Expert Comment

by:corvanderlinden
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")
or
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.

 

0
 

Expert Comment

by:nickwoolley
ID: 7230916
listening..
0
 
LVL 49

Expert Comment

by:DanRollins
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
0
 

Expert Comment

by:SpideyMod
ID: 7968386
per recommendation

SpideyMod
Community Support Moderator @Experts Exchange
0

Featured Post

Industry Leaders: 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!

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses
Course of the Month10 days, 5 hours left to enroll

762 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