VBS Part 2 – Fundamentals and Concepts

Having gone through the Introductory part, it is time to look at some crucial fundamentals and concepts. This article is to refresh some of the key facts and features of VBScript. In the least, you should consider the following six points for developing a fundamental understanding of VBScript.

Though we will cover these concepts in depth along with examples in the subsequent tutorials, but for now these brief points are enough for you to understand ‘what you can or should do with VBScript’. So without further ado, let’s jump on to these concepts.

VBScript is a Scripting Language

‘VBScript’ is a ‘scripting language’! What does this mean? Well, a vague difference between a programming and scripting is that a scripting language is not pre-compiled until runtime and hence while the end product of a programming language is mostly a compiled binary executable program (example; .exe), the end product of a scripting language is rather the source code itself (example; .vbs file)!
Hence unlike C++, VB or other compiled programming languages, the ‘VBScript’ is essentially an ‘interpreted language’ which is interpreted by ‘VBScript Engine’ at runtime i.e. every time the code is actually executed it is interpreted (or compiled internally).

For detailed explanation around interpreted and compiled languages, please refer to the earlier article ‘Interpreted Vs Compiled languages

VBScript Supports ‘Late Binding’

Since VBScript is a not a compiled language, hence natively it supports only ‘Late Binding’. Therefore unlike the ‘Early Binding’ scenario, in case of VBScript being the ‘Late Binding’ language, 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 Object’, consequently, any issues with the COM information are not discovered until actual execution. For further reading around this concept, please refer to dedicated article on ‘Early Bound Vs Late Bound

Loosely Typed Language

When it comes to ‘Data Types’, VBScript is a ‘loosely typed language’. What this means is that the programmer does not have to declare the ‘Data Type’ of variables in advance. Stating it the other way, VBScript does not provide any means for declaring the ‘Data Types’ for the variables and rather uses a generic or universal data type called the ‘Variant’ which can logically hold any type of value by means of its ‘Sub-Type’

Such a strategy of ‘having and not having data type’ simultaneously is manifested by the concept of ‘Variant’ and its ‘Sub-Type’. Summing-up this by means of a vague analogy, “all variables in VBScript have a default ‘data type called variant’ which is equivalent of ‘no data type’, however, each variant has an associated ‘Sub-Type’ which could be a string, integer, float” etc. Together they manifest the ‘having and not-having’ strategy. More details around this have been discussed in the below section

Single and Universal Data Type

As discussed above, VBScript has only one Data Type which is called the ‘Variant’. This ‘Variant’ is a special type of data type in the sense that it can logically hold almost any type of value e.g. String, Integer, Date, time etc. But this does not mean the VBScript is totally unaware about ‘Data Types’, in order to facilitate VBScript with the intelligence to recognize and deal with ‘Data Types’ it has a special feature known as the ‘SubType’. This ‘SubType’ is kind of ‘Data Type’ of the ‘Variant’ itself. For better understanding Imagine this :

When you declare a variable it automatically gets the ‘Variant’ data type assigned to it. But when you actually put some value in this variable then VBScript assigns the appropriate Sub Type (data type) for this value. You do have means to force the data types or query the data types from there onwards.

So in VBScript, you can solve the dilemma of Data Types by asking the ‘Variant’ that, what is it’s SubType. Now, this might complicate things further hence we will leave it here on the worth mentioning note that – the ‘Variant’ is the only data type supported by VBScript and hence it is the only data type returned by VBScript functions.

Object Model and Libraries

VBScript does not have any proprietary object model of its own! That is to say that if you want to access say for example ‘FileSystem’ or ‘Network’ objects and namespace, VBScript alone cannot help you. It has no way to directly talk to these resources.

But the best part is, that it can hook to most of the COM Components or Servers and exploit them to get the work done. Hence whether you need to play with databases (ADO) or XMLs (DOM) or HTML (DOM) or any other supported COM stuff, it’s a piece of cake for VBS!

Apart from being such a  COM Master, it has got some very cool good friends from the same Microsoft family; namely the ‘WSH’, ‘WMI’ and ‘Scripting Runtime Library’. You can literally get almost any scripting or automation task done on windows if you are able to make VBScript work together with these friends.

COM Enabled and COM Automation

On the last note, VBScript is a fully ‘COM-Enabled’ scripting language and hence can very well work with a variety of COM Components / Servers. The worth mentioning point is that VBScript works only with the COM Objects which implement an ‘IDispatch’ interface.

Moreover, VBScript supports COM scripting which is to say that you can create your own ‘Custom Classes’ and their methods and properties in VBScript. This gives you increased power while using VBScript. By coding ‘classes’ you can make your code more robust, modular and reusable.

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.

VBSCRIPT TUTORIALS

Recent Posts

RELATED POSTS

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

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

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

How To Sort List in Java

Introduction A List is an interface in the Java collection framework. It can be used to store objects. Programmers often encounter scenarios where they need...

Â

CHECKOUT 'HOW-TOs'

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

MORE ON CODEX

MORE IN THIS CATEGORY

Maven Common Commands Reference

Maven offers a good set of commands and CLI Options to carry out wide range of Dev tasks. Most of these commands are in...

Remove Duplicates from List Using Set.addAll

The Set interface has a method called addAll. This accepts a 'Collection' as the parameter. So if you invoke this method by passing the...

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

OTHER TUTORIALS

How To Create Dashboards with Jira

What is a Jira Dashboard? The Jira dashboard is like a control panel for your projects. You can create several...
- Advertisement -spot_img