C
Colin McGuire
Hi, I am just playing with the Hashtable class and, correct me if I am
wrong please, but is it correct to say that I have to retrieve a
specific value for a given key by creating an enumerator and process
everything until I find the key (as in my routine below getValue()) -
ie I just can't say here it the key, now give me the value? If this is
the case I would appreciate a suggestion on an alternative to class
Hashtable that I could use.
Thank you
Colin
Dim ht As New Hashtable
Private Sub populate()
ht.Add("key1", "the")
ht.Add("key2", "quick")
ht.Add("key3", "brown")
ht.Add("key4", "fox")
ht.Add("key5", "jumps")
End Sub
Private Function getValue(ByVal key As String)
Dim valueFound As String = ""
Dim en As IDictionaryEnumerator = ht.GetEnumerator()
While en.MoveNext() And valueFound <> ""
If en.Key = key Then valueFound = en.Value
End While
Return valueFound
End Sub
'And somewhere else in my program
'
Call populate()
'
'
MsgBox getValue("key4")
wrong please, but is it correct to say that I have to retrieve a
specific value for a given key by creating an enumerator and process
everything until I find the key (as in my routine below getValue()) -
ie I just can't say here it the key, now give me the value? If this is
the case I would appreciate a suggestion on an alternative to class
Hashtable that I could use.
Thank you
Colin
Dim ht As New Hashtable
Private Sub populate()
ht.Add("key1", "the")
ht.Add("key2", "quick")
ht.Add("key3", "brown")
ht.Add("key4", "fox")
ht.Add("key5", "jumps")
End Sub
Private Function getValue(ByVal key As String)
Dim valueFound As String = ""
Dim en As IDictionaryEnumerator = ht.GetEnumerator()
While en.MoveNext() And valueFound <> ""
If en.Key = key Then valueFound = en.Value
End While
Return valueFound
End Sub
'And somewhere else in my program
'
Call populate()
'
'
MsgBox getValue("key4")