JS

JavaScript Demos:
VBScript vs. JavaScript.

jim.cerny@unh.edu   13-AUG-1998


Discussion.

Microsoft supports two scripting languages for use with HTML, both JScript which is its implementation of JavaScript, and VBScript which is very similar in use and syntax except it is based on a subset of Microsoft's Visual Basic language. Microsoft describes VBScript this way:

When used in Internet Explorer, VBScript is directly comparable to JavaScript (not Java). Like JavaScript, VBScript is a pure interpreter that processes source code embedded directly in the HTML. VBScript code, like JavaScript, does not produce standalone applets but is used to add intelligence and interactivity to HTML documents. For the millions of programmers who already know Visual Basic, VBScript is a valuable alternative to JavaScript in activating web pages.
Note that wording. Explorer supports VBScript while Netscape does not.

Here is a simple example of a script to display a welcome message on a Web page, based on the time of day. First is a JScript version, then a VBScript version, both taken from the Microsoft samples area. They are listed sequentially below, but you can also click on each of the following links to bring them up in separate JScript and VBScript windows for side-by-side comparison.


<SCRIPT LANGUAGE="JavaScript"> <!-- // These next lines of code execute when the script tag is parsed. var d = new Date() var h = d.getHours() if (h < 12) document.write("Good morning!") else if (h < 17) document.write("Good afternoon!") else document.write("Good evening!") document.write("<br><br>Welcome to the world of JScript. ") document.write("<br>Just in case you were wondering, it's " + d + ".") //--> </SCRIPT>
<SCRIPT LANGUAGE="VBScript"> ' This line executes when the script tag is parsed. Call PrintWelcome Sub PrintWelcome Dim h h = Hour(Now) If h < 12 then Document.Write "Good morning! " ElseIf h < 17 then Document.Write "Good afternoon! " Else Document.Write "Good evening! " End If Document.Write "Welcome to the world of VBScript. " Document.Write "Just in case you were wondering, it's " Document.Write Time() & " on " & Date() & "." End Sub </SCRIPT>