News:

GinGly.com - Used by 85,000 Members - SMS Backed up 7,35,000 - Contacts Stored  28,850 !!

Main Menu

Adding VB Script to Web Pages

Started by thiruvasagamani, Jul 12, 2008, 03:28 PM

Previous topic - Next topic

thiruvasagamani

What is VBScript?

VBScript, Microsoft's Visual Basic Scripting Edition, is a scaled down version of Visual Basic. While it doesn't offer the functionality of Visual Basic, it does provide a powerful, easy to learn tool that can be used to add interaction to your web pages.

If you are already experienced in either Visual Basic or Visual Basic for Applications, you will find working with VBScript easy and should be immediately productive. Don't be concerned if you haven't worked in another version of Visual Basic. VBScript is easy to learn, even for the novice developer.

Adding VBScript to Web Pages


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 <SCRIPT> Tag

You add scripts into your 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 shown below:

<HTML>

<HEAD>

<TITLE>Working With VBScript</TITLE>

<SCRIPT LANGUAGE="VBScript">

  MsgBox "Welcome to my Web page!"

</SCRIPT>

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.

While technically you can place scripts throughout an HTML document using pairs of <SCRIPT> tags, typically scripts are often found at either the top or bottom of a Web document. This provides for easy reference and maintenance.

Handling Non-Supporting Browsers

Not all browsers support scripting languages. Some only support JavaScript. Only Microsoft's Internet Explorer supports VBScript. You might be wondering what happens to your scripts when non-supporting browsers encounter them. Usually browsers will do what they do most frequently with text, they will display your scripts as part of the web page. Obviously, this isn't the result you had hoped for. One simple way to address this problem is to encase your scripts in comment tags (<!-- and -->). Below is our example script as it appears with the addition of the comment tags:

<HTML>

<HEAD>

<TITLE>Working With VBScript</TITLE>

<SCRIPT LANGUAGE="VBScript">

<!--

  MsgBox "Welcome to my Web page!"

-->

</SCRIPT>

</HEAD>

</HTML>

Now, when a browser that does not support VBScript processes this page, it will view your script as a comment and simply ignore it.

Thiruvasakamani Karnan