TKC Blog
29

Hash tables are a great way to store and retrieve lists of values that have different data types.  You can retrieve items in the list by their given text key.

 See examples below:

 Function ShowHashTable() As String
 
    ' Create a new hash table
    Dim htParams As New Hashtable
    Dim strTemp As String
 
    ' Add some entries to the hash table, entries can be different data types
    htParams.Add("Firstname", "Freddy")
    htParams.Add("Surname", "Tester")
    htParams.Add("Age", 40)
 
 
    ' Iterate through items and display the hashtable
    strTemp = "<table>"
 
    For Each deEntry As DictionaryEntry In htParams
 
      strTemp &= "<tr><td>" & deEntry.Key & "</td><td>" & deEntry.Value & "</td></tr>"
 
    Next
 
    strTemp &= "</table>"
 
    ' Refer to individual items in the hash table like this:
    strTemp &= "My name is: " & htParams("Firstname") & "<br />"
 
    ' Change items in the hash table like this:
    htParams("Age") = 33
 
    strTemp &= "My age is: " & htParams("Age")
 
    Return strTemp
 
 End Function

 

 

Search Blog