Home All Groups Group Topic Archive Search About

Access collection using key

Author
25 May 2005 4:54 AM
Ant
Hi, I've set up a collection to keep track of forms. I've used the forms
caption as the key to each object in the collection to keep track of which
forms are stored in it. My question is how can I now use the key to determine
if that form has already been loaded? I can loop through the collection but I
only seem to be able to reference the count which doesn't seem to help my
problem. Any suggestions would be much appreciated

Ant

Author
25 May 2005 10:40 AM
Markus Weber (Megalith GmbH)
Set FormFormCol = colForms(strYourKey)

should do what you want. If this line of code fails the form is not
included in the collection.

By the way, there is no need to create such a collection by yourself.
VB already offers the "Forms" collection which might be exactly what
you need.

Show quoteHide quote
>Hi, I've set up a collection to keep track of forms. I've used the forms
>caption as the key to each object in the collection to keep track of which
>forms are stored in it. My question is how can I now use the key to determine
>if that form has already been loaded? I can loop through the collection but I
>only seem to be able to reference the count which doesn't seem to help my
>problem. Any suggestions would be much appreciated
>
>Ant
Author
25 May 2005 1:10 PM
Ant
Hello Marcus,
Thanks very much; That did it. I also looked for the forms collection but I
couldn't find such an object 'Forms'. I'm using VB6 (SP3). You might be
referring to .NET (?)
Doesn't really matter as this collection does fine.
Thanks again.


Show quoteHide quote
"Markus Weber (Megalith GmbH)" wrote:

> Set FormFormCol = colForms(strYourKey)
>
> should do what you want. If this line of code fails the form is not
> included in the collection.
>
> By the way, there is no need to create such a collection by yourself.
> VB already offers the "Forms" collection which might be exactly what
> you need.
>
> >Hi, I've set up a collection to keep track of forms. I've used the forms
> >caption as the key to each object in the collection to keep track of which
> >forms are stored in it. My question is how can I now use the key to determine
> >if that form has already been loaded? I can loop through the collection but I
> >only seem to be able to reference the count which doesn't seem to help my
> >problem. Any suggestions would be much appreciated
> >
> >Ant
>
>
Author
25 May 2005 1:59 PM
Bob Butler
"Ant" <A**@discussions.microsoft.com> wrote in message news:B209CFFB-
7C3F-4C65-AB6F-8860F07AC***@microsoft.com
> Hello Marcus,
> Thanks very much; That did it. I also looked for the forms collection
> but I couldn't find such an object 'Forms'. I'm using VB6 (SP3).

The Forms collection is a standard part of VB6.. add this to your code
somewhere:

dim f as form
for each f in Forms
  debug.print f.Name
next

--
Reply to the group so all can participate
VB.Net: "Fool me once..."
Author
25 May 2005 2:58 PM
Jeff Johnson [MVP: VB]
"Bob Butler" <tiredofit@nospam.com> wrote in message
news:u01P9HTYFHA.3212@TK2MSFTNGP10.phx.gbl...

>> Thanks very much; That did it. I also looked for the forms collection
>> but I couldn't find such an object 'Forms'. I'm using VB6 (SP3).
>
> The Forms collection is a standard part of VB6.. add this to your code
> somewhere:
>
> dim f as form
> for each f in Forms
>  debug.print f.Name
> next

Does the Forms collection have a key or is it only accessible by index? I'm
betting on the latter, so it won't solve the poster's original problem.
Author
25 May 2005 3:11 PM
Bob Butler
Show quote Hide quote
"Jeff Johnson [MVP: VB]" <i.get@enough.spam> wrote in message
news:u4J8DpTYFHA.1412@TK2MSFTNGP12.phx.gbl
> "Bob Butler" <tiredofit@nospam.com> wrote in message
> news:u01P9HTYFHA.3212@TK2MSFTNGP10.phx.gbl...
>
>>> Thanks very much; That did it. I also looked for the forms
>>> collection but I couldn't find such an object 'Forms'. I'm using
>>> VB6 (SP3).
>>
>> The Forms collection is a standard part of VB6.. add this to your
>> code somewhere:
>>
>> dim f as form
>> for each f in Forms
>>  debug.print f.Name
>> next
>
> Does the Forms collection have a key or is it only accessible by
> index? I'm betting on the latter, so it won't solve the poster's
> original problem.

It only works by index but it'd be easy enough to loop through the
collection looking for the desired form.  Even with a lot of forms it would
not take long.  I was only responding to the part that said he "couldn't
find such an object 'Forms'" though.  Building his own collection should
work just fine also.

--
Reply to the group so all can participate
VB.Net: "Fool me once..."
Author
26 May 2005 2:36 AM
Michael D. Ober
VB 6 has a Forms collection.  VB.Net uses native Windows API based forms and
as such, doesn't have a forms collection.  This is probably the single
biggest difference between VB 6 and VB.Net.

Mike Ober.

Show quoteHide quote
"Ant" <A**@discussions.microsoft.com> wrote in message
news:B209CFFB-7C3F-4C65-AB6F-8860F07AC8F7@microsoft.com...
> Hello Marcus,
> Thanks very much; That did it. I also looked for the forms collection but
I
> couldn't find such an object 'Forms'. I'm using VB6 (SP3). You might be
> referring to .NET (?)
> Doesn't really matter as this collection does fine.
> Thanks again.
>
>
> "Markus Weber (Megalith GmbH)" wrote:
>
> > Set FormFormCol = colForms(strYourKey)
> >
> > should do what you want. If this line of code fails the form is not
> > included in the collection.
> >
> > By the way, there is no need to create such a collection by yourself.
> > VB already offers the "Forms" collection which might be exactly what
> > you need.
> >
> > >Hi, I've set up a collection to keep track of forms. I've used the
forms
> > >caption as the key to each object in the collection to keep track of
which
> > >forms are stored in it. My question is how can I now use the key to
determine
> > >if that form has already been loaded? I can loop through the collection
but I
> > >only seem to be able to reference the count which doesn't seem to help
my
> > >problem. Any suggestions would be much appreciated
> > >
> > >Ant
> >
> >
>
Author
26 May 2005 1:25 PM
Bob Butler
"Michael D. Ober" <ober***@.alum.mit.edu.nospam> wrote in message
news:4Dale.643$MI4.401@newsread2.news.pas.earthlink.net
> VB 6 has a Forms collection.  VB.Net uses native Windows API based
> forms and as such, doesn't have a forms collection.  This is probably
> the single biggest difference between VB 6 and VB.Net.

I think it'd be difficult to identify any *single biggest difference*!

--
Reply to the group so all can participate
VB.Net: "Fool me once..."