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?
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?
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.
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'.
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.
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.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
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.
I couldn't find anything like 'array.sort' in Access. I'm happy though with the solution, thanks.