From: Pramod on
Hi All,

I have following vbscript code:

--------------------------------------------------------------------------------------------------------------------------------------------
set sampleObject = CreateObject("SampleType") -- COM component proxy
set hddObject = sampleObject.GetAllHDDs("comp1")

--------------------------------------------------------------------------------------------------------------------------------------------

GetAllHDDs function returns a list of objects (List<>). How do I
iterate through all the objects from the list?
Also I want to pass the same object to another function.

Any help is appreciated.

Thanks,
PSI

From: mayayana on
You seem to be mixing languages. "component
proxy" sounds like .Net. And I've never seen the
notation "List<>". I know that in .Net just about
everything is thought of as an object, but in
VBScript an object is specific. It's a COM Dispatch
interface. Other data types are not objects.

So you don't have a "List of objects" and they
may not actually be objects. :) It's hard to know
without more info. and with you not being familiar
with COM.

If it returns some kind of grouping then that
must be either an array or a Collection. You can
use For/Each iteration with either of those, although
the more standard way to handle arrays is by index.
An array member can be accessed by the notation
array(index). A collection member can be accessed
by the notation Collection.Item(key).

You might want to download the scripting help files:

http://www.microsoft.com/downloads/details.aspx?FamilyId=01592C48-207D-4BE1-
8A76-1C4099D7BBB9




>
> I have following vbscript code:
>
> --------------------------------------------------------------------------
------------------------------------------------------------------
> set sampleObject = CreateObject("SampleType") -- COM component proxy
> set hddObject = sampleObject.GetAllHDDs("comp1")
>
> --------------------------------------------------------------------------
------------------------------------------------------------------
>
> GetAllHDDs function returns a list of objects (List<>). How do I
> iterate through all the objects from the list?
> Also I want to pass the same object to another function.
>
> Any help is appreciated.
>
> Thanks,
> PSI
>


From: Richard Mueller [MVP] on

"Pramod" <ipramod(a)gmail.com> wrote in message
news:3da897c0-87ab-456b-8959-385977b00519(a)e4g2000prn.googlegroups.com...
> Hi All,
>
> I have following vbscript code:
>
> --------------------------------------------------------------------------------------------------------------------------------------------
> set sampleObject = CreateObject("SampleType") -- COM component proxy
> set hddObject = sampleObject.GetAllHDDs("comp1")
>
> --------------------------------------------------------------------------------------------------------------------------------------------
>
> GetAllHDDs function returns a list of objects (List<>). How do I
> iterate through all the objects from the list?
> Also I want to pass the same object to another function.
>
> Any help is appreciated.
>
> Thanks,
> PSI
>

If GetAllHDDs returns a collection (array) of objects, I would enumerate in
a For Each/Next loop as follows in VBScript:

For Each objHDD In sampleObject.GetAllHDDs("comp1")
Wscript.Echo "Name: " & objHDD.Name
Next

and access whatever properties and methods are exposed.

--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--


From: mayayana on
>
> If GetAllHDDs returns a collection (array) of objects, I would enumerate
in
> a For Each/Next loop as follows in VBScript:

Not to split hairs, but that might be confusing
to the OP, who seems to be unfamiliar with the
terminology.

A Collection is an object but not an array. An
array is not an object or a Collection. Their methods
are similar enough to be confusing but not quite
the same. An array is linear, contiguous storage
accessed by index. A Collection is an object with
items stored by Key. I think it always has an Item
and Count property, and has Add, Remove methods
when relevant. Members can be accessed via
Col.Item(key) or Col.Item(index).

As I'm writing this I'm thinking about how
confusing it must be for new people, because
the For/Each enumeration method can be used
with both arrays and Collections, and For/Each
with a Collection doesn't use the Item property,
while the index enumeration does:

For i = 1 to Col.Count
x = Col.Item(i)
' or Set x = Col.Item(i)

But index enumeration with an array doesn't:

For i = 0 to UBound(Array1)
x = Array1(i)
' or Set x = Array1(i)

And that gets into the inconsistencies
of when Set has to be used.....or the
issue of lower bound.... :)




From: Christoph Basedau on
Pramod schrieb:
> Hi All,
>
> I have following vbscript code:
>
> --------------------------------------------------------------------------------------------------------------------------------------------
> set sampleObject = CreateObject("SampleType") -- COM component proxy
> set hddObject = sampleObject.GetAllHDDs("comp1")
>
> --------------------------------------------------------------------------------------------------------------------------------------------
>
> GetAllHDDs function returns a list of objects (List<>). How do I
> iterate through all the objects from the list?

Everything in .NET and also COM that goes by the name of
Collection, List, Array most likely implements some kind
of IEnumerable-interface.
There are two of these interfaces in .NET and some in COM,
they're all subtly different, but share the ability of
being "ForEach-able". That is: You can iterate such an object
in a For Each loop getting one of its items returned
in each step.

set sampleObject = CreateObject("SampleType") -- COM component proxy
set hddCollection = sampleObject.GetAllHDDs("comp1")
For Each hddItem in hddCollection
WSH.Echo "here's the next item of type: " & typename(hddItem)
Next

> so I want to pass the same object to another function.

So you should pass it to that function, you don't have to
worry 'bout types or calling conventions in VBScript.
It's all passed by ref and wrapped into variants.

Christoph