Gmail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
Handle list of objects in vbscript
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  5 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Pramod  
View profile  
 More options Nov 14 2009, 2:40 pm
Newsgroups: microsoft.public.scripting.vbscript
From: Pramod <ipra...@gmail.com>
Date: Sat, 14 Nov 2009 06:40:05 -0800 (PST)
Local: Sat, Nov 14 2009 2:40 pm
Subject: Handle list of objects in vbscript
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


    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
mayayana  
View profile  
 More options Nov 14 2009, 3:20 pm
Newsgroups: microsoft.public.scripting.vbscript
From: "mayayana" <mayaXXy...@rcXXn.com>
Date: Sat, 14 Nov 2009 10:20:18 -0500
Local: Sat, Nov 14 2009 3:20 pm
Subject: Re: Handle list of objects in vbscript
  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-207...
8A76-1C4099D7BBB9

> I have following vbscript code:

> --------------------------------------------------------------------------

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

> --------------------------------------------------------------------------

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


    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Richard Mueller [MVP]  
View profile  
 More options Nov 14 2009, 5:05 pm
Newsgroups: microsoft.public.scripting.vbscript
From: "Richard Mueller [MVP]" <rlmueller-nos...@ameritech.nospam.net>
Date: Sat, 14 Nov 2009 11:05:51 -0600
Local: Sat, Nov 14 2009 5:05 pm
Subject: Re: Handle list of objects in vbscript

"Pramod" <ipra...@gmail.com> wrote in message

news:3da897c0-87ab-456b-8959-385977b00519@e4g2000prn.googlegroups.com...

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


    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
mayayana  
View profile  
 More options Nov 14 2009, 7:56 pm
Newsgroups: microsoft.public.scripting.vbscript
From: "mayayana" <mayaXXy...@rcXXn.com>
Date: Sat, 14 Nov 2009 14:56:17 -0500
Local: Sat, Nov 14 2009 7:56 pm
Subject: Re: Handle list of objects in vbscript

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


    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Christoph Basedau  
View profile  
 More options Nov 14 2009, 11:21 pm
Newsgroups: microsoft.public.scripting.vbscript
From: Christoph Basedau <cbase...@hotmail.de>
Date: Sun, 15 Nov 2009 00:21:20 +0100
Local: Sat, Nov 14 2009 11:21 pm
Subject: Re: Handle list of objects in vbscript
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


    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2010 Google