
Iterate through a hashtable, a get an object by Position
I may be wrong but if the hash table collection works the same way as in
C#,
there is no warranty that the second element will be "two" or the third
element will be "three" etc. I have a feeling he want the element in the
collection to retain the location in the order in which they were entered
and I don't think this is going to happen with a hash table.
Quote:
> Hi James!
> >Hashtables allow you to retrieve data by index using ITEM:
> > x = ThisFields.Item("RequiredLevel").DBColumnName
> >This returns the object because I know the key name.
> >However, these key names are not always known.
> >I want to be able to iterate through the objects without knowing the
names.
> >Of simply grab the 5th one for example.
> >Any ideas?
> In VB, you can iterate through the hashtable using a For Each statement,
> such as:
> Dim h As New System.Collections.Hashtable()
> h.Add("one", "one")
> h.Add("two", "two")
> h.Add("three", "three")
> Dim o As System.Collections.DictionaryEntry
> For Each o In h
> Debug.WriteLine(o.Key)
> Debug.WriteLine(o.Value)
> Next
> So, you should be able to For Each over the ThisFields collection and if
> you want to grab the "5th" element you will need to keep track of the
count
> through the loop.
> I hope this helps!
> Chris Dias
> Microsoft Visual Basic Team