Collection Key/Index

the_utmost

Registered User.
Local time
Today, 12:34
Joined
Mar 10, 2005
Messages
40
Hi:

I have a problem with saving two sets of data. The problem is that sometimes the corresponding value is not known until later. For instance

Collection1 Collection2
Name1 Null
Name2 Bob
Name3 Null
Name4 Ray

So I have to save Collection 1 with all 4 values and Collection 2 with only Bob and Ray. A few clicks and I know the value of Name1 and Name3. I have to insert them into my collection in the correct spots. Does anyone know how/if I can use a key or an index for this?

Currently I am using
ColName.Add "Bob",,after:=1
but that fails. Any idea's?
 
If you need the two collections to correspond as they appear to in your post, what I suggest is use only one collection, but make it a collection of a user-defined type...
Code:
Public Type myNameType
   ntID as Long
   ntName as Variant
End Type

Then create a variable of this new type...
Code:
Private MyName As myNameType

Then assign its values in a loop somewhere...
Code:
Do While Not .EOF
   With MyName
      .ntID = <yourNameID>
      .ntName = <yourNameString>   [COLOR=Green]'and since it's a variant it can be null[/COLOR]
      [COLOR=Green]'and plug each one into the collection[/COLOR]
      yourCollection.Add MyName
   End With
Loop

Lemme know if this helps,
Mark
 
Last edited:
This looks like a good idea. Now I need my collection to have public scope instead of private. Where do I make my declaration? I have a code module but this is where I am creating my collection.
 
I ended up using a 2-dimensional array. My list is 6 items max so I just created an array of this size. Thanks anyhow.
 

Users who are viewing this thread

Back
Top Bottom