You could try a function like this...
Depending on the bigger picture you might want something a little different. The raise operator (^) is very slow, it could well be a good Idea to keep a module level array of Bit values (1, 2, 4, 8... ...536870912, 1073741824, -2147483648) to use for getting/setting bits. The score gives no indication of the order of the letters, it indicates which letters are present and how long the word isCode:Private Function ScoreWord(Word As String) As Long Dim buf() As Byte, i As Long, score As Long If Len(Word) < 32 Then score = score Or (Len(Word)) * &H4000000 buf = StrConv(LCase$(Word), vbFromUnicode) For i = 0 To UBound(buf) If buf(i) > 96 And buf(i) < 122 Then score = score Or 2 ^ (buf(i) - 97) Else ScoreWord = -1 'indicates word contains illegal letters Exit Function End If Next i ScoreWord = score Else ScoreWord = -2 'indicates word is too long End If End Function
Have a look at the words and associated scores in the example. All the words with equal score are possibly an anagram of each other. For any set of letters (<32) you can generate a score and compare it to the scores in the list.




Reply With Quote