Windows IT Pro is the leading independent community for IT professionals deploying Microsoft Windows server and client applications and technologies.
  
  
  Advanced Search 


March 13, 2002

Scripting Solutions with WSH and COM: Add Line Numbers to Improve Script Debugging


RSS
View this exclusive article with VIP access -- click here to join |
See More VBScript Articles Here | Reprints | Or sign up for our VIP Monthly Pass!

When you use text editors such as Notepad to create long scripts, receiving error messages such as Error in line 162 from Windows Script Host (WSH) as it interprets the lines of code can be annoying. The messages are annoying not because the script has errors, but because you don't know which line is line 162. Now, I could have told you to buy SAPIEN Technologies' Primalscript or use Microsoft Script Debugger (which you can find in the Microsoft Windows 2000 Server Resource Kit or download from http://msdn.microsoft.com/downloads/default.asp?url=/downloads/sample.asp?url=/msdn-files/027/001/731/msdncompositedoc.xml); instead, I decided to write a script to enumerate the line numbers in .vbs files.

Laying the Groundwork
I wanted to create a script that would add line numbers to the lines of code in a .vbs file. However, I didn't want to append the numbers to the code in the original .vbs file because the line numbers would cause the code to fail. So, I needed to create a temporary file and copy the .vbs file's code into it, appending line numbers to each line of code in the temporary file during the copy. To make the script easy to use, I wanted to use the WSH drag-and-drop technology that I showed you in "Scripting Solutions with WSH and COM: Using WSH Drag and Drop to Send Faxes in Win2K," December 2001, InstantDoc ID 23041. Using this WSH technology, I created a script called ShowLineNumbers.vbs onto which I can drag other scripts to generate and open a temporary file with the contents appended by line numbers. ShowLineNumbers.vbs, which Listing 1, page 14, shows, has four distinct sections:

  • Initialization—I set up the constants and variables.
  • Arguments—I make sure the user is passing only one argument (i.e., the pathname to one .vbs file) to the script (the code at callout A in Listing 1).
  • New file creation—I create the temporary file that includes line numbers (the code at callout B in Listing 1).
  • End—I view, then delete the temporary file (the code at callout C in Listing 1).

You can download ShowLineNumbers.vbs from the Code Library on the Windows Scripting Solutions Web site (http://www.winscriptingsolutions.com). Let's go through this simple script. . . .


Already a VIP member?
Please log on to view the full article

Why become a VIP member?

VIP-only online access
VIP CD delivered twice a year: offline access to the entire Windows IT Pro article library
Monthly issue of your choice of Windows IT Pro or SQL Server Magazine

Subscribe Now
Top Viewed ArticlesView all articles
Command Prompt Tricks

One reader shares his tip for setting up the command prompt to reflect a remote path. ...

WinInfo Short Takes: Week of November 9, 2009

An often irreverent look at some of the week's other news, including some more Windows 7 sales momentum, some Sophos stupidity, Microsoft's cloud computing self-loathing, more whining from the browser makers, Zoho's "Fake Office," and much, much more ...

Understanding File-Size Limits on NTFS and FAT

A general confusion about files sizes on FAT seems to stem from FAT32's file-size limit of 4GB and partition-size limit of 2TB. ...


Scripting Whitepapers From Development to Production: Streamlining SharePoint Deployment with DocAve Deployment Manager

Related Events Check out our list of Free Email Newsletters!

Scripting eBooks Keeping Your Business Safe from Attack: Encryption and Certificate Services

Best Practices for Managing Linux and UNIX Servers

Building an Effective Reporting System

Related Scripting Resources Introducing Left-Brain.com, the online IT bookstore
Looking for books, CDs, toolkits, eBooks? Prime your mind at Left-Brain.com

Discover Windows IT Pro eLearning Series!
Clear & detailed technical information and helpful how-to's, all in our trademark no-nonsense format


Windows IT Pro Home Register FAQ for Windows WinInfo News
Europe Edition About Us Contact Us/Customer Service Media Kit Affiliates / Licensing  
SQL Server Magazine Office & SharePoint Pro DevProConnections IT Job Hound
Left-Brain.com Technology Resource Directory asp.netPRO ITTV Windows SuperSite 
 
 Windows IT Pro is a Division of Penton Media Inc.
 © 2009 Penton Media, Inc. Terms of Use | Privacy Statement