I am trying to write my own hashtable for VB6 and have hit a couple of slight stumbling blocks.
To generate the keys, I was going to sum the values of the string and go from there. Except it doesn''t like this:
Function Hash_Key(name As String) As Integer
Dim result, i As Integer
result = 0
For i = 1 To Len(name)
result = result + name(i)
Next i
Hash_Key = result
End Function
as name isn''t an array. Is there any way to treat it as an array or just get the ith character?
The second problem I have a work around for, but it troubles me. There doesn''t seem to be a way in VB to test if an array element has a value or not. If you access an element that doesn''t have a value, then an error is thrown and you catch it.
Sub Hash_Put(name As String, info As StringSet)
On Error GoTo ERRH
Dim index As Integer
Dim testSet As StringSet
Dim done As Boolean
done = False
index = Hash_Key(name) Mod hash_size
Do While Not done
testSet = Titles(index)
index = index + 1
If index >= hash_size Then
done = True
End If
Loop
ERRH:
Titles(index) = info
MsgBox "Hash_put:" & index
End Sub
This seems to me to be a bad way of doing things, so if anyone has a more non-hackish way of determining if an array element is being used or not, please post it.