Windows IT Pro is the authoritative and independent resource for windows nt, windows 2000, windows 2003, windows xp. Features a collection of resources and magazines for windows IT professionals.
  
  
  Advanced Search 


August 16, 2004

Rem: Interpolating an Array Element to Reference a Property Name


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

Q: I'm having problems with the VBScript code in Listing 3. In this script, Array1 is a dynamic array that's populated by using Windows Management Instrumentation (WMI) to retrieve the properties of the Win32_Battery class. When I try to use the contents of this dynamic array to execute a query, I get the error message Error: Object doesn't support this property or method: 'Array1.' I've tried everything I can think of to make this script work but nothing has worked. What am I missing?

A: There are several problems in your script. Before I point out the problems and suggest a possible solution, I should take a minute to clarify what the script is trying to do for the benefit of our readers. In brief, the script is trying to use Array1 as an interpolated variable, as the code at callout C in Listing 3 shows. What does that mean? In the context of scripting languages, to interpolate means to insert the value of a variable into an expression, statement, or string. Let's look at a simple example in Perl, a scripting language that supports interpolated variables. Suppose you have the following code in a script:

my $cn = "cn=tmtowtdi";
my $user = Win32::OLE->
GetObject("LDAP:\\\\$cn,...")
or die;

The snippet begins by assigning the string "cn=tmtowtdi" to the variable named $cn. Next, the code uses the value stored in the $cn variable as part of the connection string used to bind to a user object in Active Directory (AD). Notice how the $cn variable is part of the connection string. That is, the variable is embedded inside the double quoted string; there's no string concatenation or the like being used. When Perl encounters a variable name inside a double quoted string, Perl automatically inserts the variable's value at that point in the string—this is interpolation at work. . . .

Reader Comments

You must log on before posting a comment.

If you don't have a username & password, please register now.




Top Viewed ArticlesView all articles
WinInfo Short Takes: Week of November 24, 2008

An often irreverent look at some of the week's other news, including a Vista Capable dismissal request, Zune price reductions, Morrow musings, Novell and Microsoft sitting in a tree ... two years later, Yahoo!, IE 6 on Windows Mobile, and so much more ...

Command Prompt Tricks

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

PsExec

This freeware utility lets you execute processes on a remote system and redirect output to the local system. ...


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 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!

TechNet Virtual Labs
Evaluate and test Microsoft's newest products.


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 Windows Dev Pro IT Job Hound ITTV
IT Library Technology Resource Directory Connected Home Windows Excavator Windows SuperSite 
 
 Windows IT Pro is a Division of Penton Media Inc.
 Copyright © 2008 Penton Media, Inc., All rights reserved. Terms and Use | Privacy Statement | Reprints and Licensing