Windows XP Annoyances Free Open Book

Windows XP Annoyances

Previous PageNext Page

9.12 Deciphering Script Errors

One of the general disadvantages of scripts is that they are typically created with a plain-text editor, rather than a rich debugging environment used with many more sophisticated programming languages (see Section 9.13 later in this chapter). Because Notepad isn't specifically designed to understand VBScript, it can't offer any assistance with syntax (grammar) or errors while you're editing. Therefore, you must wait until you run the script to see if there are any problems. If WSH encounters an error, it will display a message similar to that shown in Figure 9-2.

Figure 9-2. The Windows Script Host displays a message like this whenever it encounters an error.

figs/xpan_0902.gif

Surprisingly, this sparse message box actually provides enough information to resolve most problems. Naturally, the first field, Script, shows the script filename in which the error occurred. This is especially useful if the script was run from a scheduled task or from your Startup folder, and you might otherwise not know which script caused the error.

The Line Number and Column fields show exactly where in the script the error occurred, and include blank lines and remarks. If you're using Notepad, select Status Bar from the View menu to display the line number at which the insertion point (text cursor) is resting. Or, select Go To from Notepad's Edit menu to quickly jump to any line. Better yet, switch to a better text editor (discussed later in this chapter) that has more debugging tools, such as numbered lines.

The Category field describes—more than anything else—what it was doing when it encountered the error. A compilation error occurs when WSH is first reading the file and making sure all of the commands are correctly entered; you'll see this if you forgot a parenthesis or quotation mark, misspelled a command, or left out some other important keyword. A runtime error , on the other hand, is an error encountered while the script was being executed; this is caused by errors that WSH doesn't know are errors until it actually tries them, such as trying to read from a file that doesn't exist or trying to calculate the square root of a negative number.

Lastly, the Description field shows a brief explanation of the error encountered. Sometimes it's helpful, but most of the time it's either too vague or too cryptic to be of much help. This is where programming experience comes in handy for interpreting these messages and figuring out what caused them. The following are a few of the more common error descriptions and what they mean:

Expected `)'

Compilation error: you left out a closing parenthesis, such as at the end of an InputBox statement (see earlier). Note that sometimes you can have nested parenthesis (e.g., x=1+(6+7*(3-4))), and you need to make sure you have an equal number of open and close parentheses.

Expected `End'

Compilation error: you left out a closing statement for a structure, such as If, Sub, or For. Make sure you include End If, End Sub, and Next, respectively. Note that WSH might report that the error occurred on line 37 of a 35-line file; this happens because in looking for a closing statement, WSH continues to search all the way to the end of the script, at which time, if the statement was not found, it will report the error. You'll have to look through the entire script for the unpaired beginning statement. See the topics on flow control earlier in this chapter (Section 9.1.3, Section 9.1.4, and Section 9.1.5) for more information on these commands.

Unterminated string constant

Compilation error: you left out a closing quotation mark, usually required at the end of a "string of text."

Invalid procedure call or argument

Runtime error: this usually means that a subroutine or function has been called with one or more improper parameters. This can occur, for example, if you try to do something WSH isn't capable of, such as calculating the square root of a negative number.

Type mismatch: `[undefined]'

Runtime error: this means you've tried to use a command or function that VBScript doesn't recognize. You'll get this error whenever you try to use a VB command that doesn't exist in VBScript.

Object doesn't support this property or method

Runtime error: because it can be difficult to find documentation on the various objects used in VBScript, you're likely to encounter this error frequently. It means that you've tried to refer to a property or method of an object (such as WScript) that doesn't exist (such as WScript.Dingus).

The system cannot find the file specified

Runtime error: This error, obviously reporting that you've tried to access a file on your hard disk that doesn't exist, also appears when you try to delete a Registry key that doesn't exist. See Section 9.3 earlier in this chapter for a Registry function that solves this problem.

ActiveX component can't create object

Runtime error: you'll get this when you try to use the Set statement, as described throughout this chapter, and for whatever reason, WSH isn't familiar with the object you're trying to initialize. Typically, objects are extensions to WSH, some of which come with Windows XP, and some of which are installed through Add or Remove Programs, and some of which come with third-party programs. The resolution usually involves installing the missing component (which usually can be found on the Web), but depends entirely upon the specific object reported by the error.

If you plan on distributing your scripts, you'll want to take steps to eliminate any error messages that may pop up. See the Section 9.4 example script earlier in this chapter for more information on error trapping and the On Error Resume Next statement.

Previous PageNext Page


     Main Menu
Cover
Copyright
Preface
Chapter 1. Making the Most of Windows XP
Chapter 2. Basic Explorer Coping Skills
Chapter 3. The Registry
Chapter 4. Tinkering Techniques
Chapter 5. Maximizing Performance
Chapter 6. Troubleshooting
Chapter 7. Networking and Internetworking
Chapter 8. User Accounts and Administration
Chapter 9. Scripting and Automation
9.1 Building a Script with VBScript
9.2 Running Applications from Scripts
9.3 Accessing the Registry from Scripts
9.4 Manipulating Files from Scripts
9.5 Creating Windows Shortcuts and Internet Shortcuts in Scripts
9.6 Networking with Scripts
9.7 Manipulating Internet Explorer from Scripts
9.8 Using Command-Line Parameters in Scripts
9.9 Managing Services with Scripts
9.10 Writing CGI Scripts for a Web Server
9.11 Making a Startup Script
9.12 Deciphering Script Errors
9.13 Finding a Better Editor
9.14 Further Study
9.15 Automating Scripts with Scheduled Tasks
9.16 Wacky Script Ideas
Chapter 10. Installing Windows XP
Appendix A. Setting Locator
Appendix B. BIOS Settings
Appendix C. Command Prompt Crash Course
Appendix D. TCP/IP Ports
Appendix E. Error Messages (Blue Screen of Death)
Colophon


More Books
PHP Hacks
Processing Xml With Java - A Guide To Sax, Dom, Jdom, Jaxp, And Trax
The Koran (Holy Qur'an)
Macromedia Flash 8 Bible
Search Engine Optimization for Dummies
YouTube Traffic
PHP 5 for Dummies
Harry Potter and The Chamber of Secrets
Harry Potter and the Sorcerer's Stone
The Pilgrim's Progress
Wireless Hacks
Flash Hacks. 100 Industrial-Strength Tips & Tools
PayPal Hacks. 100 Industrial-Strength Tips and Tools
Amazon Hacks
Pdf Hacks
The Da Vinci Code
Google Hacks
The Holy Bible
Windows XP For Dummies
Harry Potter and the Half-Blood Prince
Seo Book
Upgrading and Repairing Networks
Macromedia Dreamweaver 8 UNLEASHED
Windows XP Annoyances
Windows XP Hacks
Microsoft Windows XP Power Toolkit
Teach Yourself MS Office In 24Hours
iPod & iTunes Missing Manual
PC Hacks 100 Industrial-Strength Tips and Tools
PC Overclocking, Optimization, and Tuning - 2th Edition
PC Hardware In A Nutshell 3rd Edition
PC Hardware in a Nutshell, 2nd Edition
Upgrading and Repairing PCs
Google for Dummies
MySQL Cookbook
Teach Yourself Macromedia Flash 8 In 24 Hours
PHP CookBook
Sams Teach Yourself JavaScript in 24 Hours
PHP5 Manual
Free Games Paper Airplanes
500 Juegos Gratis 500 Giochi Gratis 500 Jeux Gratuits 500 Jogos Gratis 500 Kostenlose Spiele