Re: coding an anagram function



Hi Neil,

I think your idea is OK, it's just easier to use the ASCII code values
to generate LONGs for each text value after removing spaces and
converting to Upper case.

Public Function ISANAGRAM(TEXT1 As String, TEXT2 As String) As Boolean
Application.Volatile
TEXT1 = Replace(TEXT1, " ", "")
TEXT2 = Replace(TEXT2, " ", "")
If Len(TEXT1) <> Len(TEXT2) Then
ISANAGRAM = False
Exit Function
End If
Dim i As Long
Dim lTEXT1_Value As Long
Dim lTEXT2_Value As Long
For i = 1 To Len(TEXT1)
lTEXT1_Value = lTEXT1_Value + 2 ^ (Asc(UCase(Mid(TEXT1, i, 1))) - 64)
lTEXT2_Value = lTEXT2_Value + 2 ^ (Asc(UCase(Mid(TEXT2, i, 1))) - 64)
Next i
If lTEXT1_Value = lTEXT2_Value Then
ISANAGRAM = True
Else: ISANAGRAM = False
End If
End Function

Ken Johnson

.



Relevant Pages

  • Re: Update DB table from visual basic script
    ... Dim dbs As Database ... Public Function UpdateDB(dbName As String) As Boolean ... Public Function updateDB_fnameAs Boolean ... On Error Resume Next ' if proc does not exist then return blank string ...
    (comp.databases.ms-access)
  • Load registry hive (AdjustTokenPrivileges error)
    ... Public PrivilegeCount As Int32 ... Public Function RegLoadKey(ByVal hKey As Int32, ... String, ByVal lpFile As String) As Int32 ... Dim strKeyName As String ...
    (microsoft.public.vb.winapi)
  • Load registry hive (AdjustTokenPrivileges error)
    ... Public PrivilegeCount As Int32 ... Public Function RegLoadKey(ByVal hKey As Int32, ... String, ByVal lpFile As String) As Int32 ... Dim strKeyName As String ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Help creating object in excel VBA
    ... Dim confirm, sent As Boolean ... Dim rowColArrayAs String ... ' TODO: Call CreateEmailMsg ... Public Function GetApptRecAs String, ...
    (microsoft.public.excel.programming)
  • Help creating object in excel VBA
    ... Outlook, and using an word.doc as the message body. ... Dim confirm, sent As Boolean ... Dim rowColArrayAs String ... Public Function GetApptRecAs String, ...
    (microsoft.public.excel.programming)

Loading