Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.basic.visual.misc > #1777

Re: VB6 use of For Each with Collections

From Michael Cole <invalid@microsoft.com>
Newsgroups comp.lang.basic.visual.misc
Subject Re: VB6 use of For Each with Collections
Date 2013-05-08 10:21 +1000
Organization A noiseless patient Spider
Message-ID <kmc5jp$klr$1@dont-email.me> (permalink)
References <e741101c-d3c7-4193-9fb3-b5543f9d33f6@googlegroups.com>

Show all headers | View raw


stevegdula@yahoo.com explained :
> Hi folks,
>
> I am just trying to get my head around using the For Each ... to recurse 
> through a custom Collection object.  This is my first use of these tools.

You are not using a custom Collection object.  You are using a 
stock-standard out-of-the-box collection, which will contain variants.

> I can't seem to see a way to derive the "KEY" value assigned to a member of 
> the collection while using the For Each approach.  The Default property of 
> the collection object is the "ITEM" value.

It's not the default value, its the only value.  Key is not a property, 
it's a way of retrieving the object.  You cannot access it as a 
property.

> Declared in a module:
> Public colObject as New Collection
>
> Form code:
> Dim varValue As Variant
> Dim strValue As String
>
> 'Build simple collection
> colObject.Add "myItem01", "myKey01"
> colObject.Add "myItem02", "myKey02"
> colObject.Add "myItem03", "myKey03"
> colObject.Add "myItem04", "myKey04"
>
> For Each varValue In colObject
>    'This grabs the [Item] value because it is the default property.
>    strValue=CStr(varValue)

No.  It grabs the collection item, which happens to be a variant 
containing a string.  'Cos a string is what you added to it.

> Next

-- 
Michael Cole

Back to comp.lang.basic.visual.misc | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

VB6 use of For Each with Collections stevegdula@yahoo.com - 2013-05-07 14:22 -0700
  Re: VB6 use of For Each with Collections Michael Cole <invalid@microsoft.com> - 2013-05-08 10:21 +1000
  Re: VB6 use of For Each with Collections ralph <nt_consulting@yahoo.com> - 2013-05-07 19:39 -0500
    Re: VB6 use of For Each with Collections Michael Cole <invalid@microsoft.com> - 2013-05-08 11:48 +1000
      Re: VB6 use of For Each with Collections GS <gs@somewhere.net> - 2013-05-07 23:55 -0400
    Re: VB6 use of For Each with Collections Deanna Earley <dee.earley@icode.co.uk> - 2013-05-08 09:19 +0100
      Re: VB6 use of For Each with Collections stevegdula@yahoo.com - 2013-05-08 08:27 -0700
        Re: VB6 use of For Each with Collections ralph <nt_consulting@yahoo.com> - 2013-05-08 11:25 -0500
          Re: VB6 use of For Each with Collections ralph <nt_consulting@yahoo.com> - 2013-05-08 11:52 -0500
            Re: VB6 use of For Each with Collections stevegdula@yahoo.com - 2013-05-08 12:00 -0700
      Re: VB6 use of For Each with Collections "Eduardo" <mm@mm.com> - 2013-06-30 22:48 -0300
        Re: VB6 use of For Each with Collections ralph <nt_consulting@yahoo.com> - 2013-06-30 22:09 -0500
          Re: VB6 use of For Each with Collections Schmidt <ng@vbRichClient.com> - 2013-07-01 07:58 +0200
            Re: VB6 use of For Each with Collections "Eduardo" <mm@mm.com> - 2013-07-01 03:47 -0300
          Re: VB6 use of For Each with Collections "Eduardo" <mm@mm.com> - 2013-07-01 04:08 -0300
        Re: VB6 use of For Each with Collections "Eduardo" <mm@mm.com> - 2013-07-01 04:01 -0300
          Re: VB6 use of For Each with Collections vincent.belaiche@gmail.com (Vincent Belaïche) - 2013-07-05 06:30 +0200
            Re: VB6 use of For Each with Collections "Eduardo" <mm@mm.com> - 2013-07-05 03:31 -0300

csiph-web