Host your site on our high performance virtual domain and non-domain accounts.
|
Using VBScript Published on 6/8/97 VBScript, or Visual Basic Scripting Edition, is a powerful and easy-to-use alternative to JavaScript for programming on the web. This article will give you an overview of using VBScript on your web site. Please take note that VBScript, and the sample scripts in this article, only function properly in Internet Explorer 3.0 or higher. Netscape Navigator does not support VBScript without the use of a third-party plugin. If you have any Visual Basic experience, you will find VBScript very similar and as just simple to use. First of all, any scripts used on a web page must be surrounded in the <SCRIPT> tag. This tag also uses the LANGUAGE attribute to distinguish between VBScript and JavaScript. It's also a good idea to use comment tags around the script to prevent older browsers from displaying gibberish. This is what a script will look like:
Now all you have to is create the script. As mentioned earlier, VBScript is very similar to Visual Basic. The individual procedures that you create are signified by the Sub and End Sub statements. The best way to illustrate this is by using an example. The following sample script displays a message dialog when you click on the button. The button's NAME attribute is set to 'DisplayMsg.' Click on this button for the demonstration: The actual code for the script is as follows:
Because the code is too wide for this page, the lines between the Sub and End Sub statements should actually be on one line, not two. Notice that since the button is named 'DisplayMsg' in the HTML source, you use Sub DisplayMsg_onClick to signify the event occurring when the user clicks the button. The MsgBox syntax is the same as it is in Visual Basic, if you are familiar with it. There are many more powerful things VBScript can do, but since this article is meant to be an overview, we'll stick to relatively simple uses of VBScript. Another common application of VBScript is to display information on the screen. You can accomplish this with a button and a text box. The following sample will display a short message in the text box when you click on the button. This time, the button is named 'DisplayText,' and the text box is named 'TextField.' Here is the demonstration: The following code was used in this sample:
As you may have noticed, we needed to refer to the text box as Sample2.TextField. This is only to inform the browser which form the text box resides in. In this case, the form was named 'Sample2.' So far, both samples have been relatively straight-forward and consistent with many Visual Basic programming conventions. The final script we'd like to demonstrate is a little more Internet-specific than the others. It is also used quite frequently on many web sites. This last script will demonstrate how you can transfer the user to another web site by using VBScript. Once again, we will use a form button to accomplish this. This time, it will be named 'GoButton.' Here is the demonstration; although, you may want to finish reading this article before you click the button, as it will transfer you to another page: This is the code that was used:
With VBScript, you can use the window.location.href property to specify the page that should be displayed in the browser. In this case, we set the property to http://www.netpanel.com, to transfer you to Netpanel's home page. Any URL can be used in place of this one. The quotation marks are necessary. As you have seen, VBScript can be used for a variety of functions with relative ease. Use these examples to get going; after that, expand on them and create your own unique scripts. Just remember the basics described in this article, and off you go! Visit Microsoft's VBScript web site for more information at http://www.microsoft.com/vbscript/ |
| Home | About | Feedback
| Downloads | Search Copyright © Michael Yigdall and Jonathan Strine |