Metamorphing Machine I rather be this walking metamorphosis
than having that old formed opinion about everything!

The rise and fall of VBScript

The good

VBScript was launched in 1996. It was and still is a Windows-only technology.
One could see it as VB6's little brother: It was untyped - every variable could only be Variant - and some VB6's features were missing.
We'll talk more about the missing bits later, but the bits that were there where promising.

In 1998 it was upgraded to version 5.0, and it smelled like VB6's future.
It had a Class keyword. Instead of defining classes in files with .CLS extension, as we are forced to in VB6, you could simply define one like this:

Class Employee
(...)
End Class

We got a Default keyword. No more messing with "advanced" procedure IDs. Just elegantly add it to a property. For instance:

Class Employee
Dim Name_

Public Default Property Get Name
Name = Name_
End Property

Public Property Let Name(Value)
Name_ = Value
End Property
End Class

It came with regular expressions. VBScript lacked the Like operator, but now you had a more powerful replacement:

NameToCheck = (...)
Set Re = CreateObject("VBScript.RegExp")
Re.Pattern = "([^a-záéíóúàãõçâêô '!@#$%¨&()-_=+`´{~^},.;[])+"
Re.IgnoreCase = True
Set Match = Re.Execute(NameToCheck)
If Match.Count > 0 Then (...)

It introduced an object-oriented way to deal with files and folders. Enough with Open, Close, Dir, etc.
We gained access to the console and its input, output, and standard error streams.
And a triplet equivalent to Javascript's eval function: Eval, Execute, and ExecuteGlobal.
There was even a way to kind of get a function pointer - GetRef! Oh, my!

As time went by, things were getting better and better. You could create .WSF files and interop with Javascript - actually, JScript, Microsoft's version of Javascript, but, still.
You could concoct an .HTA file and have a stand-alone SPA. In 1999!

The bad

Three VB6 features are missing in VBScript that hurt the most.
The first one is annoying but work-aroundable: IIf (Immediate If). For such a simple function, there is no excuse it is not included in VBS.
One can just slap a quicky:

Function IIf(Expression, TruePart, FalsePart)
If Expression Then IIf = TruePart Else IIf = FalsePart
End Function

Then, one can remember it does not deal properly with objects, so it needs fixing:

Function IIf(Expression, TruePart, FalsePart)
If Expression Then
If IsObject(TruePart) Then Set IIf = TruePart Else IIf = TruePart
Else
If IsObject(TruePart) Then Set IIf = FalsePart Else IIf = FalsePart
End If
End Function

And then one would need to remember to copy-and-paste it everywhere. As I said, annoying.
The other ones are lack of GoTo and proper error handling.

In VB6, there are three ways to handle errors:
For VBS, you can only opt to not handle the errors - then your script crashes and burns when one happens -, or ignore it. In my not-so-humble-opinion, none of these options is acceptable. There's no way you can write professional scripts limited to these options.
The recommended way to deal with errors is less than optimal:

On Error Resume Next
DoSomething
If Err Then (...)
DoAnotherThing
If Err Then (...)


(Golang, anyone?)
Without a GoTo, what can be after the Then in the code above? You can quit running the procedure, but this would not be better than not handling the error.
You can have a very deep nested sequence of Ifs, but it would not be practical.
What else?

The ugly

Then, with the advent of the .NET Framework, Microsoft put VBScript in maintenance mode. And with the coming of PowerShell, it started to suggest you should use it instead of VBS.
It is still available in Windows 10 and will be for the foreseeable future.

But its heydays are gone.

Andrej Biasic
2020-06-24