As VBScript's popularity increased, it found its way into just about every Microsoft environment available. Also, the language expanded, to include regular expressions, object-oriented programming principles, and other advanced features. By version 5 of the language, it was capable of doing just about anything other major languages were capable of.
With the advent of the .NET framework, Microsoft decided to fold VBScript into that framework. Due to its inclusion in .NET, VBScript is nearly universally available in Microsoft environments.
Interestingly, for as much as VBScript has expanded its reach over the last two decades, there is one place where it is no longer available: the browser. VBScript was never available in non-Microsoft browsers. The last version of Internet Explorer to include support for VBScript was version 10. Internet Explorer 11, and the new Microsoft Edge browser, do not support VBScript. (Actually, it is possible to run VBScript in Internet Explorer 11, if you turn on compatibility mode. But this isn't recommended.)
VBScript is a general-purpose scripting language, and could, in theory, be used for any number of purposes. However, most VB script usage falls into a small handful of categories:
- Systems administration: administrators of various Microsoft systems were among the first adopters of VBScript, as it was a marked improvement over earlier alternatives. It continues to be used by sysadmins, and its use is somewhat analogous to the use of Bash or Perl among Linux administrators. VBScript is beginning to be displaced by PowerShell in this area, but VBScript continues to be used quite a lot.
- Testing: VBScript is used in Quick Test Professional (now called Unified Functional Testing), a popular unit testing suite.
- Embedded devices" VBScript is also relatively popular among developers of embedded applications (user interaction software built into custom purpose devices).
- Macros and in-app scripting: VBScript also gets a fair amount of use within other Microsoft applications, such as MS Office.
VBScript and Web Development
Even though in-browser use has been scant (and is no longer supported), the browser-based features of VBScript can be exploited in the context of HTML Application, a Windows app format that allows a desktop UI to be built in HTML and powered via one or more scripting languages. This approach is fairly popular among Windows sysadmins and developers, as it allows them to get a prototype up and running pretty fast. (This desktop use of HTML dating back to the late 1990s prefigures the rise of modern app engines like Electron , NW.js , and PhoneGap ).
Language and Examples
Below we will provide a very basic introduction to the language.
VBScript is primarily a functional language. It supports classes and objects, but not dogmatically so. Early versions of the language did not support classes and other object-oriented features. Standard logic and control-flow structures are available, as are a wide variety of data types.
The main "unit" of programming is the procedure. There are function procedures and sub procedures. Sub procedures do not return a value, but can perform actions.
Unlike Visual Basic, VB does not have much ability to define a GUI. It can create simple popup alerts, but a form-based application would need something like HTML or XML to define the UI.
VBScript has to be run in a supported environment. For server-side web development, that environment is ASP. For systems automation, it is usually the Windows Script Host.
VBScript was based on Visual Basic, so its syntax is most similar to that. Visual Basic was based on BASIC, and retained many syntax features from that language. If you learned to program in BASIC, VBScript will probably look at least somewhat familiar.
Variables should be declared using the
dim keyword before they are used. You can specify the variable type, or leave it undefined until a value is assigned.
Dim greeting Dim recipient As String Dim message greeting = "Hello" recipient = "World!" message = greeting & " " & recipient document.write(message)
Comments in VBScript are single-line only, and are defined by a leading single apostrophe (
' This is a comment.
if statements, and other code-blocks are declared with a key word statement and ended with the
'simple if statement if x > y then wsh.echo "X is Greater" end if
Should I Learn VBScript?
If you are an IT professional or Systems Administrator working in a Microsoft environment, you probably should be familiar with VBScript, and its use as a system automation tool. Even though you can use PowerShell and other languages, you will likely encounter older automation and testing scripts written in VBScript, which you will need to maintain, debug, or rewrite.