Adding VBScript to Web Pages


© Maxim Karetnikov

Getting started

VBScript, also known as Visual Basic Scripting Edition,  requires absolutely nothing which is not freely available on the Internet.  In fact, most computers already have most of what is needed.  The tools necessary for writing VBScript are as follows:

  1. A plain text editor.  Any word-processor which does not leave extra-marks (e.g.,   Notepad for Windows or Pico for Unix) will do. Some that are available for download are SitePad or JPad and NoteTab.  Most HTML editors will works as well, provided that they let you edit the HTML source.
  2. An Internet Browser which supports VBScript.  Right now, that means Internet Explorer Version 3 or higher.  The latest version is available for free download from Microsoft. If you have advanced WYSIWYG HTML editor (like MS FrontPage, Hot Meal, etc.) you might use them to edit script and to view the results.

The <SCRIPT> Tag

Scripting languages, like JavaScript and VBScript, are designed as an extension to HTML. The Web browser receives scripts along with the rest of the Web document. It is the browser's responsibility to parse and process the scripts. HTML was extended to include a tag that is used to incorporate scripts into HTML - the <SCRIPT> tag. The scripts are added  into the Web pages within a pair of <SCRIPT> tags. The <SCRIPT> tag signifies the start of the script section, while </SCRIPT> marks the end. An example of this is a simple program for page initialization. After the page is loaded, a message "Welcome to VB Script" appears. As in VISUAL BASIC and regular BASIC, the comments are separated from a code by apostrophe (') mark.

<HTML> 
<HEAD>
<SCRIPT LANGUAGE="VBScript"> 'Start of the script section
Sub Init() 'Start of VBScript procedure
Msgbox "Welcome to VB script" 'VBScript code
End Sub 'End of VBScript procedure
</SCRIPT> 'End of Script section
</HEAD>
<BODY onload="Init()"> 'Begins the document body
</BODY> 'Ends the document body
</HTML> 

The beginning <SCRIPT> tag includes a LANGUAGE argument that indicates the scripting language that will be used. The LANGUAGE argument is required because there is more than one scripting language. Without the LANGUAGE argument, a Web browser would not know if the text between the tags was JavaScript, VBScript or another scripting language.

You can use SCRIPT  blocks anywhere in an HTML page. As for me, I prefer put all general-purpose scripting code in the HEAD section in order to keep all the code together.This provides easy reference and maintenance of  code and ensures that all code is read and decoded before it's needed by any calls from within the BODY section.

Go To Page: 1 2


The copyright of the article Adding VBScript to Web Pages in VB Script is owned by . Permission to republish Adding VBScript to Web Pages in print or online must be granted by the author in writing.

Post this Article to facebook Add this Article to del.icio.us! Digg this Article furl this Article Add this Article to Reddit Add this Article to Technorati Add this Article to Newsvine Add this Article to Windows Live Add this Article to Yahoo Add this Article to StumbleUpon Add this Article to BlinkLists Add this Article to Spurl Add this Article to Google Add this Article to Ask Add this Article to Squidoo