What is VBScript?
VBScript is an interpreted script language from Microsoft that is a subset of its Visual Basic programming language designed for interpretation by Microsoft's Internet Explorer (IE) web browser. VBScript compares to other early scripting languages that were used for the web development, including the following:
- Sun Microsystem's Tcl
- Unix-derived Perl
- IBM's REXX
VBScript functionality is available in Microsoft's Edge browser for users who need to run a legacy web application that contains VBScript code. This is done using IE mode and changing the version of IE to IE10 in the operating system's group policy function.
Scripting languages are easier and faster to code compared to more structured compiled languages such as C and C++. They are ideal for smaller programs of limited capability or that can reuse and tie together existing compiled programs.
How is VBScript used?
VBScript was mainly used to give functionality to webpages. It was originally used for client-side scripting in IE. Web developers could write and embed executable VBScript functions in the Hypertext Markup Language (HTML) of a webpage, which controls the presentation of data. VBScript was able to do things that HTML alone couldn't, such as generate data.
VBScript uses a component object model to access system objects and variables. It has been generally used in a Microsoft environment. Since Microsoft disabled it, VBScript has limited use. It is still used in some situations, such as the following:
Disadvantages of VBScript
VBScript also runs in Microsoft's Internet Information Services -- Microsoft's web server -- and the Windows Script Host environment.
Other disadvantages of VBScript are the following:
- It only works on Windows. A website containing VBScript can't be loaded on a Linux or Mac system.
- It has limited command line.
- There is no development environment.
- VBScript has been the target of cybersecurity attacks. One example is the ILOVEYOU virus, which was a hidden VBScript program that users would mistake for a harmless text file. Once the file is opened, it deletes all files on the user's machine.
Until IE's retirement, users could write a simple piece of VBScript code using IE -- preferably IE6 or later -- and any text editor. VBScript code was embedded in HTML code to modify dynamic websites.
Below is a simple example of VBScript embedded in HTML.
<html> <head> <title>VBScript Tutorial!!!</title> </head> <body> <script type="text/vbscript"> document.write("VB script tutorial!") </script> </body> </html>
The above code writes the text "VB script tutorial!" to a webpage. The phrase document.write tells the computer to write the string between the quotes on the page.
The user can save this code as an HTML file to their machine, and it will open in IE. To do this, the user can set their default browser to IE and double click the saved file. The text "VB script tutorial!" should display in the body of the webpage after the file opens.
Below is an example of the syntax used in VBScript to write a conditional statement.
Dim a, b, c a = 1 b = 5 c = (a<=10) If c = True Then response.write("Looks right to me") Else response.write("Nope") End If
If the value of a is less than or equal to 10, the program will print the phrase "Looks right to me." If the variable is greater than 10, it will respond "Nope." The phrase End If is used to finish the conditional statement.
Other differences between the two scripting languages include the following: