Delphi function port

I’m converting this Delphi hash function:

[code]Function TDSimpleHash(const aKey: String; aTablesize: integer): integer;
var
i: integer;
Hash : longint;

begin
Hash := 0;
for i := 1 to length(aKey) do
Hash := ((Hash * 17) + ord(aKey[i])) mod aTablesize
Result : = Hash;
if (Result < 0) then
inc(Result, aTablesize)
end;[/code]

Xojo:

[code]Public Function SLSimpleHash(aKey as String, aTableSize as Integer) as Integer
Dim i As Integer
Dim Hash As Integer

Hash = 0
For I = 0 To Len(aKey)-1
Hash = ((Hash * 17) + Asc(Mid(aKey,I)) Mod aTablesize
Next

Return Hash

End Function[/code]

I get an error on the Hash = ((Hash * 17) + Asc(Mid(aKey,I)) Mod aTablesize

Anybody?

You’re missing a ) just before Mod.

You’re kidding me… I looked it over 100 times. Thanks
#feelingstupid

When I deep-nest one liners like that, I always use the add - subtract parenthesis count method, starting at zero and adding one for each open and subtracting one for each close, so your original code would have resulted in:

0 1 2 1 2 3 2 1

This identifies that I’m short one closing parenthesis.

Of course, I still need to figure out where :D.

[quote=430618:@Tim Jones]When I deep-nest one liners like that, I always use the add - subtract parenthesis count method, starting at zero and adding one for each open and subtracting one for each close, so your original code would have resulted in:

0 1 2 1 2 3 2 1

This identifies that I’m short one closing parenthesis.

Of course, I still need to figure out where :D.[/quote]
I follow a same pattern but sometimes you overlook things. Cheers.

That’s why I use spaces to see what belongs with what:

Hash = (  (Hash * 17)  +  Asc( Mid(aKey,I) )  )  Mod aTablesize