Programming Windows: Hello, VBScript (Premium)

Microsoft created VBScript as a simpler alternative to JavaScript that was based on its vast experience with the BASIC programming language. The scripting language had little success in the browser since it was only supported by Internet Explorer. But with the software giant also creating its own web server and bringing its COM technologies online as ActiveX, VBScript played an important role in “activating the Internet.”

We’ve already looked at client-side scripting—that is, scripts that in a web page that are executed by the browser—in Programming Windows: Hello, HTML (Premium) and Programming Windows: Hello, JavaScript (Premium). In both cases, the scripting language was JavaScript, which was and still is broadly supported in all web browsers. JavaScript is a standard and the lingua franca of the web, and it is inarguably the single most popular programming language in the world.

But in 1996, Microsoft was still pushing to embrace the Internet across all of its product lines, and it embraced and extended JavaScript in two ways, with its own version called Jscript, which was largely compatible with the original language, and with VBScript, which was based on a version of the Visual Basic language called Visual Basic for Applications (VBA).

As you may recall, one could write a simple hello, world script in JavaScript (or JScript) and HTML like so:

<HTML>
<HEAD>
    <TITLE>Hello, JavaScript!</TITLE>
</HEAD>
<BODY>
<SCRIPT>
    document.write("<H1>Hello, JavaScript!</H1>");
    document.write("<P>JavaScript is the glue that makes the web work.</P>");
</SCRIPT>
</BODY>
</HTML>

A version in VBScript would look very similar.

<HTML>
<HEAD>
    <TITLE>Hello, VBScript!</TITLE>
</HEAD>
<BODY>
<SCRIPT LANGUAGE="VBScript">
    document.write("<H1>Hello, VBScript!</H1>")
    document.write("<P>VBScript is a Microsoft alternative to JavaScript.</P>")
</SCRIPT>
</BODY>
</HTML>

The only real difference in the code is the addition of the VBScript language attribute in the <SCRIPT> tag and the removal of the semicolons, since VBScript, like VB and VBA, didn’t require line endings. And sure enough, it works identically to the JavaScript version.

OK, that’s not very interesting, I know. And it was even less interesting in the 1990s because, again, client-side VBScript didn’t work in Netscape Navigator, which was by far the most popular web browser. In fact, Navigator would simply ignore VBScript, so the page above would render as blank.

Because of this limitation, few web developers ever embraced VBScript for client-side scripting. And even when Internet Explorer overtook Navigator in usage, it made sense to stick with JavaScript, which worked in all browsers.

One issue with client-side scripting, of course, was that anyone could see your source code: All browsers supported a way to display the underlying HTML and scripting code (and still do).

The solution was server-side scripting that would work on the website backend and emit plain HTML, hiding the underlying logic from users. This enabled developers to create more sophisticated solutions, including dynamic websites in which the information being presented—news articles, perhaps—was stored in a database, accessed from a server-side scripting language or software component, and then published to users in HTML.

Microsoft answered this need with its Internet Information Server (IIS) web server and a technology called Active Server Pages (ASP), which brought VBScript and JScript to the server. ASP arrived with IIS 3.0 in late 1996. IIS 4.0, a significant upgrade, came a year later, adding Transaction Server 2.0, Message Queue Server 1.0, Certificate Server 1.0, Internet Connection Services for RAS, new data access components, Site Server Express, Internet Explorer 4.01 (with the Windows Shell Update), and Service Pack 3 (SP3) for Windows NT 4.0. A CD-ROM version of the pack arrived in early 1998, adding a stripped-down Personal Web Server 4.0 for web developers that ran on Windows NT Workstation and Windows 95.

With IIS and ASP, one could create special ASP documents that combined HTML and VBScript (or JScript). These documents were interpreted by IIS when loaded by a user in a web browser, allowing the scripts to execute and emit plain HTML. The scripting code would be contained in <% and %> tags and could be interspersed anywhere in the HTML code. Like so:

<%@ Language=VBScript %>
<html>
<head>
<title>Hello, VBScript and ASP!</title>
</head>

<body>
<p><img SRC="win2000.gif" WIDTH="456" HEIGHT="124"></p>
<% For i = 3 To 7 %>
<font SIZE="<% = i %>">
Hello, VBScript and ASP!<br>
</font>
<% Next %>

</body>
</html>

This example uses HTML to display a GIF file that Microsoft provided with IIS 4.0 and then uses a VBScript For Next loop to display the text Hello, VBScript and ASP! in five different font sizes.

What’s most interesting here is that anyone viewing the source code for the page would only see the HTML. The scripting code used to generate that HTML was hidden from the user.

This was useful. But the most common use for VBScript and ASP was accessing content in databases to create dynamic websites. For example, the following code uses ActiveX technologies called Active Data Objects (ADO) and OLE DB to interface between VBScript/ASP and a backend Access database called Northwind.

<%@ Language=VBScript %>
<HTML>
<HEAD>
<TITLE>Database access with ASP, ADO and OLE DB</TITLE>
</HEAD>

<BODY>
<H1>Database access with ASP, ADO and OLE DB</H1>
<PRE><%
Set objConnection = Server.CreateObject("ADODB.Connection")
objConnection.Open "Provider=Microsoft.Jet.OLEDB.3.51;Data Source=" & _
                    Server.Mappath("/Website_Local/db/NWIND.mdb")
SQLQuery = "SELECT * FROM Customers"
Set rsCustomers = objConnection.Execute(SQLQuery)
%>
</PRE>

<% Do Until rsCustomers.EOF %>
<%= rsCustomers("CompanyName")%><BR>
<%= rsCustomers("ContactName")%><BR>
<%= rsCustomers("Address")%><P>
<% rsCustomers.MoveNext %>
<% Loop %>

</BODY>
</HTML>

Like the previous example, this code uses a loop, in this case, a Do Until loop, to cycle and emit HTML code. But in that loop, it is accessing the data stored in the Customers table in the Northwind database with a SQL statement. SELECT * FROM Customers literally grabs all (“*”) of the data in that table. The result is a plain text listing of the requested fields in Customers with some basic HTML formatting.

Normally, one would format the output a bit, of course. For example, you could use an HTML table, like so:

<TABLE>
    <% Do Until rsCustomers.EOF %>
    <TR>
        <TD BGCOLOR="#EEEEEE" ALIGN="LEFT"><FONT SIZE="5">
            <%= rsCustomers("CompanyName")%><BR>
        </TD>
        <TD BGCOLOR="#EEEEEE" ALIGN="LEFT"><FONT SIZE="5">
            <%= rsCustomers("ContactName")%><BR>
        </TD>
        <TD BGCOLOR="#EEEEEE" ALIGN="LEFT"><FONT SIZE="5">
            <%= rsCustomers("Address")%><P>
        </TD>
    </TR>
    <% rsCustomers.MoveNext %>
    <% Loop %>
</TABLE>

The resulting output is perhaps more familiar looking.

As it turns out, I used IIS and ASP to create some of the first dynamic websites, starting in 1996. Among them was the Internet Nexus, which hosted my WinInfo news and information mailing list. (This was eventually moved to its own website called WinInformant and was then incorporated into Windows NT Magazine’s website in January 1999 when it and the SuperSite for Windows were purchased by that publication’s owner, Duke Publishing.)

Thinking back on this time, I hunted down an old version of my WinInfo database (from 1999) and wrote some ASP code that published all of its contained articles to the web. I did this using Visual InterDev, a Microsoft web development tool I used (and wrote books about) in the late 1990s, running on Windows 2000 and IIS. This isn’t the same code I used at the time; I wrote this fresh instead and compared it with what I had written over 20 years ago after the fact. But what I came up with looks like so.

<%@ Language=VBScript %>
<HTML>
<HEAD>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<TITLE>WinInfo</TITLE>
</HEAD>
<BODY>

<H1>WinInfo</H1>

<PRE><%
Set objConnection = Server.CreateObject("ADODB.Connection")
objConnection.Open "Provider=Microsoft.Jet.OLEDB.3.51;Data Source=" & _
                    Server.Mappath("/db/WININFO.mdb")
SQLQuery = "SELECT * FROM tblWinInfo ORDER BY DATE DESC"  
Set rsWinInfo = objConnection.Execute(SQLQuery)
%>
</PRE>

<% Do Until rsWinInfo.EOF %>
<h2><%= rsWinInfo("Title")%></h2>
<%= rsWinInfo("Date")%><P>
<%= rsWinInfo("Body")%><P>
<% rsWinInfo.MoveNext %>
<% Loop %>

</BODY>
</HTML>

The only big difference between this code and the previous examples of ASP-based database access is that I’m outputting the article contents in reverse order so that the most recent article is displayed first. (The ORDER BY DATE DESC bit in SELECT * FROM tblWinInfo ORDER BY DATE DESC achieves this.) It’s also not formatted in any meaningful way.

This was personally pretty exciting. But my more impressive accomplishment from 1996, perhaps, was creating a basic (by today’s standards) Content Management System (CMS) on our web server that I could use to add articles to the database with a web-based form. This CMS also supported other features one uses today in products like WordPress, such as the ability to list, find, and edit existing articles. I used this CMS for WinInfo and for other sites we published at the time, like HipMama.

Looking at my 20+ year old code today, I can see that I used different data access methods—Microsoft changed this technology a lot in the late 1990s as it continued to race to embrace the Internet—and that we eventually evolved the code to include ActiveX components for database access and SQL Server instead of Access (both for performance reasons). My code of the day was also more sophisticated than what you see above, and it of course includes a lot of HTML and CSS (Cascading Style Sheet) formatting

As noted, I wrote about this work in various books at the time, and I would like to believe that I helped at least a few people “activate the Internet” using Microsoft technologies that were both technically impressive and fun. And because it all ran on the server, the resulting web pages were 100 percent compatible with all web browsers, unlike Microsoft’s client-side scripting and ActiveX controls.

What a time.

Gain unlimited access to Premium articles.

With technology shaping our everyday lives, how could we not dig deeper?

Thurrott Premium delivers an honest and thorough perspective about the technologies we use and rely on everyday. Discover deeper content as a Premium member.

Tagged with

Share post

Thurrott