I want to port this simple hash algorithm to VB6.
I have come up with:
Public Function simpleHash(hashString As String) As Long
Dim hash As Long
Dim c As Long
Dim i As Integer
On Local Error Resume Next
hash = 5381
For i = 1 To Len(hashString)
c = AscW(Mid$(hashString, i, 1))
hash = hash * 33 + c
Next i
simpleHash = hash
End Function
The problem is, despite my On Error
statement which suppresses the Error 6: Overflow exceptions, the variable hash
is not updated any more if an overflow occurs.
How can I fix that or implement this algorithm differently?