Solved

Late Binding

Posted on 2002-06-19
11
537 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 50 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
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 
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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

730 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