VB Script – Introduction
Vb Script tutorials will be covered in the following topics which are given below :
• What is VB Script ?
• Working with Variables?
• Objects and VB Script ?
• Controlling VB Script Routines ?
• Using VB Script with Forms?
In this tutorial you will learn about VB Script – What is VB Script ? Introduction, Description, How to Add VB script to web pages ? The Script Tag, How to handle Non Supporting Browsers and Conclusion
What is VB Script ?
Introduction :
VB Script is a scripting language developed by Microsoft. With the help of this scripting language you can make your web pages more dynamic and interactive.
VB Script is a light version of Visual basic and it has an easy syntax.
Description :
VB Script is widely used and most popular as a client side scripting language. In html language you use < and > around the tags. But you can use many tags inside one pair of < % and % >. For Printing a variable you can use < % = % >.
How to Add VB script to web pages ?
There are scripting languages like Javascript and Vbscript and they are designed as an extension to html language.The Web browsers like Microsoft Internet Explorer receives the scripts along with the rest of the web page document. It is the browser responsibility to parse and process the scripts. These scripts are widely used as a client side scripting languages. Now you will start learning how the Script language works and we will show you step by step . So just concentrate on the further topics.
The Script Tag
When ever you want to add scripts in your web pages you are preparing you have to use < script > starting tag and < / script > ending tag where the script is going to close. The example of this is shown below :
< html > < head > < title >vbscript example< /title > < script language=”vbscript” > Msgbox “Welcome to the world of VB Script” < /script > < /head > < body > < /body > < /html > |
I have used the example with a simple going “Welcome to the world of vbscript” as there is a tendency whenever a new learner is learning a new language we always welcome him.
Well, in the above example you have seen the language attribute. We have used VbScript as the scripting language.This Argument is required as there are more than one scripting language. Without the language argument, browser would not able to know if the text between the tags was vbscript or javascript or any other scripting language.
As the Script is totally dependent on the browser so next question arises is “ How to handle Non Supporting browsers”. If the client browser has disabled the script than your web page might now function properly. So for your advantage you can also the server side language. As the server side language is far from the scope of this tutorial.
How to handle Non Supporting Browsers
As not all browsers are compatible for scripting languages . As Vbscript is only supported by Microsoft Internet Explorer.So you might be thinking of the Non Supporting browsers. The Non Supporting browsers does not know how to handle this script part, so they will display all the script as part of your text on a web page. To resolve this Issue you can encase your script in the Comments tag as given in the below example.
< html > < head > < title >vbscript example< /title > < script language=”vbscript” > Msgbox “Welcome to the world of VB Script” < /script > < /head > < body > < /body > < /html > |
Now, When the Web browsers that does not support the scripting language will view your script as a comment and will simple ignore it.
The easiest way to learn any new language is to work on it.So we will use maximum examples so that you can practice more.
< html > < head > < title >First vbscript example< /title > < /head > < body > < form name="firstexample" > < Input type="button" name="cmdclickMe" value="Just Click" > < SCRIPT FOR="cmdClickMe" EVENT="onClick" LANGUAGE="VBScript" > MsgBox "A simple example of VBScript in action." < /SCRIPT > < /form > < /body >< /html > |
Save the above code with any name but with the extension .html and run it in your browser.You will see the result like in the below picture when you click button Just Click. This is functionality of the script.
As in the above example we have the script just after the html button created. But this is not the preferred approach and will lead to confuse state when the web pages are too large. So to avoid complexity and to ease the readablitiy of the web page document the below given approach is far better.
< html > < head > < title >First vbscript example< /title > < SCRIPT LANGUAGE="VBScript" > Sub cmdclickMe_onClick MsgBox "A simple example of VBScript in action." End Sub < /SCRIPT > < /head > < body > < form name="firstexample" > < Input type="button" name="cmdclickMe" value="Just Click" > < /form > < /body >< /html > |
I will explain you how it is working.The only difference of this code from the above code is that we have shifted our script tag to the head section in the html for easy readability. Just read the script tag here we have defined a sub procedure called cmdclickMe . This will be executed everytime the button is clicked as onClick event is attached with it. It means the script has to be executed everytime the button is clicked. Its simple.The output generated will be the same as in the previous example.
Conclusion
We have learned how to add script to the web pages.
How to make your script not available to the non supporting browsers.