Home > Articles

The Fundamentals of VBScript

  • Print
  • + Share This

The Fundamentals of VBScript

VBScript and ASP go hand in hand. VBScript is one of the two most prominent languages you can use to program server-side, dynamic behavior into the ASP pages you create. You can use JavaScript to work on the server-side, however, many Windows programmers who have prior knowledge of Visual Basic find it easier to use VBScript to do server-side ASP programming. VBScript is not case sensitive and the syntax is easy to master. JavaScript, on the other hand, is case sensitive and although it is a more compact language, similar to C, sometimes beginning programmers have trouble getting the nuances of the syntax.

When it comes to writing script that executes on an unknown, client-side browser, JavaScript is the way to go. Remember, at the present time, Netscape Navigator does not support VBScript. Using JavaScript on the client side ensures that your code will execute regardless of whether the browser is Internet Explorer or Netscape Navigator. However, using VBScript on the sever side makes your programming effort a lot easier.

In this chapter you will

  • Create variables using VBScript

  • Work with Arrays and Collections

  • Make statements in VBScript

  • Create Subs and Functions

  • Work with Event Procedures

Before we go on, let's make one thing perfectly clear: Programming is programming, regardless of whether you are writing code in Visual Basic, VBScript, JavaScript, C++, Pascal, or Java. Sometimes, developers who use a scripting language as their main means of expression feel as if they are not really programmers, that they are not as smart or as adept as developers who use other languages such as Java or C++. Don't be fooled. It takes just as much discipline, talent, thoughtfulness, and creativity to make a well-designed program in VBScript as it does in C++. Yes, mastery of language is important, but what you do with the language is more important.

Now that this little misconception is out of the way, let's take an overview of VBScript and a brief peek at JavaScript.

Using <SCRIPT></SCRIPT> tags

You use the <SCRIPT></SCRIPT> tags when you want to insert script in a Web Page. The Language= attribute defines the language in which the script within the tags is written. You have a choice of VBScript or the Microsoft type of JavaScript, JScript. You can use the <SCRIPT></SCRIPT> tags to denote both client-side or server-side script. If you want your script to be executed on the client side, use the RUNAT=Server attribute within the <SCRIPT></SCRIPT> tags.

Listing 3.1 shows you a set of <SCRIPT></SCRIPT> tags for some client-side VBScript. This script is executed when the user clicks a specific button, button1, on a Web page running in a client-side browser. Don't worry about the meaning of the code. The important thing to observe here is the use of the Language attribute.

Listing 3.1: <SCRIPT></SCRIPT> Tags Using VBScript (03asp01.htm)

  Sub button1_OnClick()
    Alert text1.value
  End Sub

Figure 3.1 shows the results of the code when the user clicks the button on the Web Page.

Figure 3.1 You can use VBScript to display a browser's Alert dialog box.

  • + Share This
  • 🔖 Save To Your Account

Related Resources

There are currently no related titles. Please check back later.