Results 1 to 7 of 7
  1. #1
    ronymaxwell is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Feb 2012
    Posts
    6

    Solving Anagrams with Access


    I have a crossword solver which uses 'Like' to search a word list for matches to inputs with wildcards. I want to add an anagram solver but can't see a way to do it. I've got close by manipulating strings but can't quite manage it. Any ideas?

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,646
    Google: VB anagram solver

    I bet someone has already done this and posted code somewhere.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    ronymaxwell is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Feb 2012
    Posts
    6
    Quote Originally Posted by June7 View Post
    Google: VB anagram solver

    I bet someone has already done this and posted code somewhere.
    I've already done that. There are plenty of standalone downloads and one for Excel, but nothing in Access. Couldn't even find anything in VBA.

    I've tried populating a table with words of the required length using [code>] DoCmd.RunSQL "INSERT INTO tempTable(tempWord) SELECT fWord FROM wordList WHERE Len(fWord) = " & L & ";" [<code] where L is the word length and fWord the field containing dictionary words.

    I then deleted words which didn't have the letters in the searched word in them using [code>] DoCmd.RunSQL "DELETE * FROM tempTable WHERE Mid$(tempWord, " & i & ", 1) Like " & Chr$(34) & "[!" & s & "]" & Chr$(34) & ";" [<code] where s is the inputted search word as a string. I repeated this for each letter.

    This almost works, but it can't handle words with more than one instance of any particular letter. For instance searching for anagrams of 'SAPS' gives 'ASPS', 'PASS' and 'SPAS' but also 'PAPA', 'PAPS' and 'SASS'. I've thought of going through all the possible combinations of the word before searching the word list, but as the words grow in length, this would be huge.

    I have now added a further step. [code>] DoCmd.RunSQL "DELETE * FROM tempTable WHERE Instr(1, tempWord, '" & r & "', 1) = 0;" [<code]. This is repeated for each letter where r is the individual letter in the searched word. It gets rid of 'PAPA' and 'SASS' in the above example but not 'PAPS'.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,646
    Also, count each letter in SAPS and if that count not found in the candidate match, remove it.

    I Googled: VB anagram solver

    Look at this thread http://www.vbdotnetforums.com/window...lp-please.html

    Then I Googled: VBA array.sort

    Review http://www.cpearson.com/excel/SortingArrays.aspx
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    ronymaxwell is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Feb 2012
    Posts
    6

    Thumbs up Thanks Super Moderator

    Quote Originally Posted by June7 View Post
    Also, count each letter in SAPS and if that count not found in the candidate match, remove it.

    I Googled: VB anagram solver

    Look at this thread http://www.vbdotnetforums.com/window...lp-please.html

    Then I Googled: VBA array.sort

    Review http://www.cpearson.com/excel/SortingArrays.aspx
    Super Moderator, thank you. The QSortInPlace is just what I need. I'd already found the first link but didn't want to use Excel, similar for the first option on the second link, but the second option is perfect.

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,646
    Even though code may be written with Excel in mind, can sometimes be adapted to Access. I didn't look at the referenced code in depth but that has helped me get code ideas before.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    ronymaxwell is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Feb 2012
    Posts
    6
    Quote Originally Posted by June7 View Post
    Even though code may be written with Excel in mind, can sometimes be adapted to Access. I didn't look at the referenced code in depth but that has helped me get code ideas before.
    I couldn't find anything like 'array.sort' in Access. I'm happy though with the solution, thanks.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 9
    Last Post: 03-26-2012, 10:35 AM
  2. Help in Solving Warranty Period in Access
    By vdanelia in forum Access
    Replies: 4
    Last Post: 01-29-2011, 04:28 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums