To use VBScript, you need to have the right tools. The following sections provide a brief rundown of some items that make working with VBScript easier.
The VB Scripting Engine
The Script code is interpreted and executed by a scripting engine. The scripting engine for VBScript is a file named VBSCRIPT.DLL, located in the \Windows\System directory. VBScript is installed with one of the applications that use it, such as Internet Explorer, Outlook, Internet Information Server, or the Windows Scripting Host. However, a few different versions of VBScript have been released, and some of the examples in this chapter may not work with VBScript versions prior to 3.0. To determine the version you have installed, right-click the VBSCRIPT.DLL file in Explorer and choose Properties, as shown in Figure 30.4.
Make sure that you are using the latest VBScript engine by checking the properties of VBSCRIPT.DLL.
Another indication that your version of VBScript is old is an error when you attempt to use an intrinsic constant (such as vbYesNo in the earlier example) because these constants were not included in the first version. If you want to upgrade to the latest version of VBScript, visit the Web site at http://www.microsoft.com/vbscript. This site contains downloadable files for the latest scripting engines that you can place on your Web site, as well as documentation for the VBScript language.
The applications with which you can use VBScript are also known as hosts for VBScript. The most common hosts are Internet Explorer and Internet Information Server. Outlook also uses VBScript as its macro language. In addition, Microsoft recently introduced the Windows Scripting host, which allows you to run VBScript code from a regular Windows platform such as Windows NT or Windows 95.
Internet Explorer hosts VBScript that runs on the user's desktop. VBScript does not currently run in Netscape Navigator. However, VBScript in Active Server Pages runs on Internet Information Server, allowing you to use VBScript to create browser-independent HTML or generate browser-specific pages on the fly.
Although the VBScript language works the same everywhere, each host application exposes a different set of objects to VBScript. So some of the statements that work in IE do not work in IIS and vice versa.
Many people who use VBScript with Web pages use a simple text editor to enter VBScript code because VBScript does not (yet) have its own integrated development environment. This means that all the great IDE features you are used to in regular VB are not available. You have to be careful that what you enter is spelled and formatted correctly. Some more advanced text editors, such as HomeSite, help you with VBScript code entry by providing automatic color-coding and toolbar buttons for commonly used statements.
Although a text editor as simple as Notepad will work, I recommend one that shows you line numbers. When an error occurs in your code, Internet Explorer returns the line number, as shown in Figure 30.5.
When an error occurs in your VBScript code, Internet Explorer displays the offending line number, which you can use to track down the error.
By leaving the text editor and browser open at the same time, you can easily switch back and forth between them. This is one way to debug VBScript: Edit and save the code, and then click the Refresh button on the browser to try again.
Advanced Web Tools
If you get tired of just using a text editor, you may want to try some of the more advanced Web tools, such as the following:
ActiveX Control Pad. A free tool from Microsoft. It is really not that advanced, but it does provide a way to get class IDs for ActiveX controls.
Microsoft FrontPage. A Web page creation application. FrontPage includes a Script Wizard, which creates VBScript code for you and makes working with ActiveX controls and events easy.
Visual InterDev. Another Microsoft product, aimed more at developers of database-driven Web pages. It generates VBScript code for you.
Internet Client SDK. Software development kit that is available for downloading from Microsoft. It provides samples, documentation, and utilities for working with the Internet.