Early Bound Vs Late Bound (Binding)

What is Binding

Before we dive into ‘Early’ and ‘Late’ stuff, let us discover, what the ‘Binding’ itself means?
In simple terms, the ‘Binding’ refers to the way a script or an application accesses a COM Automation object. This is manifested as the association of entities such as data, program, procedures etc. with identifiers.

It is done when the application is compiled and all functions called in code must be bound before the code can be executed. In the premise of VBScripting, when a script or application attempts to create an instance of a COM object, it inherently verifies the existence of the object in the relevant or specified namespace besides this the object’s methods and properties (called in the script) are also verified. This entire process of locating and verification while creating an instance of COM Object is called ‘Binding’.

Binding with VBScript

Here are some typical examples of binding –

Set MyObject = CreateObject ("Word.Application") 
Set MyObject = GetObject ("winmgmts:") 
Set MyObject = WScript.CreateObject ("Scripting.FileSystemObject")

In general, there are two methods to bind to a COM object using VBScript syntax as specified below (other variations exist as well depending upon the specific needs or style) –

  • CreateObject (“[Component or Server or Moniker][.][Object or typename]”)
  • GetObject (“[Component or Server or Moniker][.][Object or typename]”)

However, if you wish to use purely WSH scripts, then the syntax would slightly change to accommodate the prefix – ‘WScript’ and as in ‘WScript.CreateObject’ and ‘WScript.GetObject’.

What is the difference between the above two methods, i.e. CreateObject and GetObject again requires a good explanation which may be out of scope of this post. But in short – ‘You should use GetObject while using monikers and if the object to which you are binding exists outside the ‘File System’ namespace examples would be WMI and ADSI. For all other purposes CreateObject should do fine

Coming back to Early and Late terms, the ‘COM’ support two types of binding –

COM Binding Types Explained

1Early Binding :With this type of binding the ‘COM Object’, its methods and properties are all checked when the script or program is compiled. This has some obvious advantages. Firstly any problems with ‘COM Object’ binding if exist makes the compilation to fail and hence results in the early discovery of related issues. Secondly, this provides the advantage of early access to object model and library (COM) and hence the related information is loaded itself into the compilation or the program. Lastly, as obvious scripts or programs supporting ‘Early Bindinding’ are relatively faster.

2Late Binding : Since VBScript is a not a compiled language, natively it supports only ‘Late Binding’. Hence unlike the ‘Early Binding’, in case of VBScript the binding does not occur until the program is actually executed. In this scenario the program usually performs frequent registry or namespace lookups upon execution to access the information about the ‘COM Objects’, consequently any issues with the COM information are not discovered until the actual execution of the script/program.

Tushar Sharma
Tushar Sharmahttps://www.automationdojos.com
Hi! This is Tushar, the author of 'Automation Dojos'. A passionate IT professional with a big appetite for learning, I enjoy technical content creation and curation. Hope you are having a good time! Don't forget to subscribe and stay in touch. Wishing you happy learning!

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Recent Posts

RELATED POSTS

How To Load XML File into DOM Using MSXML

Microsoft XML Core Services (MSXML) provides two methods for loading XML documents into the Document Object Model (DOM) and one method and one property...

Interpreted Vs Compiled Languages

This is based on an excerpt from one of my favourite literature on VBScript and in fact, is quite relevant with respect to one...

How To Convert String To Date in Java

Introduction There are often scenarios in programming, where you will need to convert a date in String format to an actual Date object. For example,...

Â

RECENT 'HOW-TO'

How To Install Oh-My-Posh On Windows PowerShell

Oh-My-Posh is a powerful custom prompt engine for any shell that has the ability to adjust the prompt string with a function or variable. It does not...

SIMILAR ON CODEX

FEATURED PROJECTS

Windows JDK Manager (win-jdk-Manager)

ADjo LABS PROJECT : Simple and lightweight desktop utility with Interactive cmd Interface for easy view, re-point and switching between JAVA versions on windows. Demonstrating the capability...

MORE IN THIS CATEGORY

Setting Max/Min Digits For Decimal Numbers With Java DecimalFormat

The DecimalFormat class offers the following four such methods which can be used to easily set the maximum and/or minimum digits for decimal numbers....

Concatenate Strings Using String.join() for Collections

There is an overloaded version of the String.join method that accepts as parameter an Iterable implementation. Since all Collection classes implement the Iterable interface,...

Configuring Maven Compiler Plugin (Java)

1. What is Maven Compiler Plugin The ‘Maven Compiler Plugin’ or more commonly known as 'Maven Java Compiler' is used to compile the source code...

CHECKOUT TUTORIALS

Finding Web Elements with Selenium

I'm going to explain in this tutorial about the usage of the findElement and findElements method of Selenium Webdriver on the Chrome web browser....
- Advertisement -spot_img