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

What is In-Proc and Out-Proc (COM) ?

The terms 'In-Proc' and 'Out-Proc' are to describe the kind of implementation of COM Servers. Before we begin, for those who are not quite...

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...

How To Concatenate Strings in Java

Introduction In Java, a String is a sequence of characters. There are often programming situations where you will need to concatenate Strings. There are several...

Â

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

Format Decimal Numbers Using Pattern

The java.text.DecimalFormat class is used to format numbers using a user specified formatting. This concrete subclass of NumberFormat, allows formatting decimal numbers via predefined...

How To Write Windows Environment Variables With VBScript

This is in continuation to the last post where we saw how to read windows environment variables using VBScript. As mentioned in the last...

Java Tutorial #2 – Operators in Java

Table of Contents Introduction 1. Assignment Operator 2. Arithmetic Operators 3. Compound Operators 4. Increment & Decrement Operators 5. Relational Operators 6. Logical Operators Introduction Operators are an essential...

CHECKOUT TUTORIALS

Getting Started with Selenium WebDriver

Table of Contents 1. Selenium and Selenium Web Driver 2. Setting-Up the Environment 3. Test Script with Selenium Web Driver 3.1) Creating a project 3.2) Creating...
- Advertisement -spot_img