?
Solved

AutoComplete  A  Word

Posted on 2003-03-04
3
Medium Priority
?
250 Views
Last Modified: 2010-05-01
I need a function that checks a global collection of words for the best match for auto completing a word that is passed to it  to teh largest number of matchiong common characters. E.g If the collection contains
sheep
ship
dog
elephant
elephants

Input        output
-----       ------
s      -->   sh (since all words with s start with sh)
sh      -->sh(since next chr is not knwon &can be i or e)
shi      -->   ship
d or do  -->   dog
dog      -->   dog    
e, el,ele ,elep etc --> elephant
elephant --> elephant
x-->x ( no match found)


Any ideas on how I should match? I was thinking :

Function autoComplete(word As text)
Dim i
For i = 1 To allWords.Count
     ' The collection is created fresh for each call to this function
     ' Remove all words that dont match
  If (Left(allWords(i), Len(word)) <> word) Then allWords.Remove i
Next i

'only 1 match
If allWords.Count =1 Then
     autoComplete=  allWords(1)
     Exit Function
End If

' Now the collection contains only matches (s->sheep,ship)
' How can I get the the common part (sh) ?

End Function
0
Comment
Question by:sambha03
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 

Accepted Solution

by:
yeeeooowww earned 200 total points
ID: 8070212
Function autoComplete(word As text)
Dim i, j
For j = 0 To Len(word)
For i = 1 To allWords.Count
    ' The collection is created fresh for each call to this function
    ' Remove all words that dont match
 If (Left(allWords(i), j) <> Left(word, j)) Then allWords.Remove i
Next i
Next j

'only 1 match
If allWords.Count =1 Then
    autoComplete=  allWords(1)
    Exit Function
End If
End Function


This should do it for you..
Basically I am trying to check for one more character after I reduce the collection size by the no of words that match for every iteration of the j loop (which depends on the length of the word) . Ofcourse you might want to list the entire word match and you can't use the function per se, but can modify it to stop iterating the entire length by passing the iteration count to the function and usign that as the j loop's max value instead of length.


eg:

Function autoComplete(word As text)
Dim i
For i = 1 To allWords.Count
    ' The collection is created fresh for each call to this function
    ' Remove all words that dont match
 If (Left(allWords(i), len(word)) <> word) Then allWords.Remove i
Next i
End Function

this should work better if you call the function with the word everytime the user types a character in the text box..etc

don't return anything.. just do a count on the colletion and display all the values there... this should return to you the max string matched.
0
 
LVL 3

Expert Comment

by:DocM
ID: 8072854

This source code shows you how to provide parameters and an autocomplete feature to your program, just like in Visual Basic! When the user is typing, a listbox appears listing the possible options. They can press the space bar to have the word completed for them, carry on typing, or select another item on the list.
http://www.developerfusion.com/show/360/

0
 

Author Comment

by:sambha03
ID: 8089775
That shld do the trick with some modifications.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses
Course of the Month9 days, 23 hours left to enroll

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question