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

