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


December 12, 2005

How to Find Constants and Their Values

Good, Better, and Best Solutions
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!

The COM technology behind objects such as the Microsoft Scripting Runtime Library's FileSystemObject object (aka the FSO object) and Windows Script Host's (WSH's) WshShell object is what makes WSH scripts so powerful. However, the way this technology works causes scripters grief in one area: Scripts don't get access to the crucial constants embedded in objects.

If you use the FSO object's Open-TextFile method to open a file for writing or appending, you might have run into this problem. In its simplest form, this method takes one mandatory parameter—the name of a file—and opens that file so you can read it. For example, the code

Dim fso 
Set fso = CreateObject( _ 
  "Scripting.FileSystemObject") 
Set file = fso.OpenTextFile( _ 
  "C:\temp\computers.txt") 

opens C:\temp\computers.txt for reading. The OpenTextFile method has three optional parameters, one of which is the I/O mode. When you look at the documentation for using this parameter, you'll notice that it can take one of three constants: ForReading, ForWriting, or ForAppending. However, if you try to use ForAppending to open and add data to the file with code such as

Set file = fso.OpenTextFile( _ 
	"C:\temp\computers.txt", _ 
	ForAppending, True) 

VBScript will immediately give you the runtime error Invalid procedure call or argument. If you're a cautious scripter who uses Option Explicit to make sure all variables are defined, you get an even more puzzling but more accurate error message: Variable is undefined: 'ForAppending'. The problem is that you're using ForAppending as a constant, but the VBScript engine sees it as a variable. You'll receive similar error messages when you use ForReading and ForWriting. . . .


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 WinConnections and Microsoft® Exchange Connections

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 Become a VIP member of the Windows IT Pro community!
Get it all with the VIP CD and VIP access. A $500+ value for only $279!

Subscribe to Windows IT Pro!
Solve your toughest technical problems with our experts and access 10,000 + articles online. 30% off

Monthly Online Pass - Only $5.95!
Get instant access to 10,000+ articles from Windows IT Pro Magazine!


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