VBScript

 <  Day Day Up  >  


Visual Basic Scripting Edition, generally called VBScript, is a subset of the popular Visual Basic language. Because of its Visual Basic heritage, in some ways VBScript is somewhat better defined and seems to have a more stable specification than JavaScript. VBScript is less prevalent than JavaScript on the Internet, largely because VBScript is fully supported in only Internet Explorer browsers. The language can be used to provide the same functionality as JavaScript, and is just as capable as accessing the various objects that compose a Web page (termed a browser's Object Model ). Given its Internet Explorer limitation, avoid trying to use VBScript as a cross-platform scripting solution. However, used in a more controlled environment, such as an intranet, VBScript might just be what the Microsoft-oriented developer needs. The following is a sample of VBScript to give you a flavor of its syntax; this example has the same functionality as the JavaScript example given previously:

  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">   <html xmlns="http://www.w3.org/1999/xhtml" lang="en">   <head>   <title>  VBScript Example  </title>   <meta http-equiv="content-type" content="text/html; charset=ISO-8859-1" />   <script type="text/vbscript">  <!-- Sub greet_OnClick       MsgBox "Hello user! Welcome to VBScript." End Sub -->  </script>   </head>   <body>   <h1 align="center">  First VBScript Example  </h1>   <div align="center">   <form action="#">   <input type="button" value="Press Me" name="greet" />   </form>   </div>   </body>   </html>  

This is a simple example of how VBScript can be included in an XHTML file and should produce a rendering similar to the one shown in Figure 14-2.

click to expand
Figure 14-2: VBScript says hello

As in the first example, the form button named "greet" triggers an alert box that greets the user. Notice that rather than using an explicit XHTML attribute such as onclick , as was used in the JavaScript example, the VBScript example names the subroutine in a certain way to associate it with the button event; in this case, greet_OnClick . Other differences with the VBScript example include the use of the MsgBox function to create the alert window, as well as syntactical differences such as the use of parentheses. Readers familiar with Visual Basic should find this example very easy because this language is just a subset of Visual Basic proper.

Once again, though, as a client-side technology, VBScript is not really very useful because it is limited to Internet Explorer. Relying on VBScript locks out others such as Netscape, Opera, or Safari users, which is unacceptable for a public Web site. Because of this, VBScript often is limited to being used within a Microsoft-oriented intranet or on the server side, in the form of Active Server Page code (as discussed in Chapter 13). No further discussion of VBScript occurs during this client-side discussion. However, readers interested in more information about the syntax of VBScript, as well as examples, are encouraged to visit Microsoft's scripting site (http://msdn.microsoft.com/scripting/).



 <  Day Day Up  >  


HTML & XHTML
HTML & XHTML: The Complete Reference (Osborne Complete Reference Series)
ISBN: 007222942X
EAN: 2147483647
Year: 2003
Pages: 252
Authors: Thomas Powell

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net