2

I'm working with visual basic. How do i create a function to read from a list of words while typing and replace any word with the possible completed word while writing . like a t9 text function . this is the code I am working with .

Public Class Keyboard2
Private Property dval As Integer

Private Sub GoToNext_Click(sender As Object, e As EventArgs) Handles GoToNext.Click
    'when this button is pressed the next possible word will be genereated and will replace the previous word by calling the "GetWord" Sub
    GetWord()
End Sub


Private Sub GetWord()
    dval = dval + 1 ' this value is used to  ensure that there can be no error in word replacement and it separates each change. 
    Dim lastWord As String = RichTextBox1.Text.Split(" ").Last ' get the last word entered in the text box
    If dval = 1 AndAlso RichTextBox1.Text.EndsWith("top") AndAlso lastWord = "top" Then
        'To change the last word to the next possible word
        RichTextBox1.Text = String.Concat(RichTextBox1.Text.Remove(RichTextBox1.Text.Length - lastWord.Length), "topmost")
    End If
    If dval = 2 AndAlso RichTextBox1.Text.EndsWith("topmost") AndAlso lastWord = "topmost" Then
        RichTextBox1.Text = String.Concat(RichTextBox1.Text.Remove(RichTextBox1.Text.Length - lastWord.Length), "topping")
    End If
    If dval = 3 AndAlso RichTextBox1.Text.EndsWith("topping") AndAlso lastWord = "topping" Then
        RichTextBox1.Text = String.Concat(RichTextBox1.Text.Remove(RichTextBox1.Text.Length - lastWord.Length), "top")
        dval = 0
    End If
End Sub

End Class

this method may be useful to some persons and i hope you will like it but for me it is a very bad method to use because i would have to enter thousands of words manually .

would I do this with a database? and does anyone have any examples . Thanks you for your time .

VladL
  • 12,769
  • 10
  • 63
  • 83
  • you don't have the list of words yet? – Scott Selby May 26 '13 at 21:52
  • I have a list but only 100 word have been added so far .I don't want to go further with this method . it takes up a massive amount of lines and accessing the function during runtime stops the application until the "GetWord" function is run. –  May 26 '13 at 22:15
  • @RuchmairDixon : If you used the IME support, isn't that the windows's language autocomplete will did it for you ? – matzone May 27 '13 at 00:04
  • @RuchmairDixon : It sounds like use chinese support language in you app ... so use IME support – matzone May 27 '13 at 02:46

2 Answers2

2

The needed functionality is implemented for you in .NET. Just do following:

1) set the TextBox.AutoCompleteSource Property to true

2) set the TextBox.AutoCompleteMode property to Suggest

3) load the the word list from the file (you will find enough on the web) and set it to TextBox.AutoCompleteCustomSource Property similar to this:

    Dim MySource As New AutoCompleteStringCollection()
MySource.AddRange(New String() _
                    { _
                        "January", _
                        "February", _
                        "March", _
                        "April", _
                        "May", _
                        "June", _
                        "July", _
                        "August", _
                        "September", _
                        "October", _
                        "November", _
                        "December" _
                    })

textbox1.AutoCompleteCustomSource = MySource 
VladL
  • 12,769
  • 10
  • 63
  • 83
  • Wow! Top marks @Vlad L. It's awesome that this is built in, thanks for sharing! – FraserOfSmeg May 26 '13 at 22:15
  • looks good .Before i get Into this , this method will also allow me to use AutoComplete for different languages, correct? –  May 26 '13 at 22:18
  • @RuchmairDixon not sure about all languages, but this worked for cyrilic letters. Just try it, it's simple :) – VladL May 26 '13 at 22:24
  • @RuchmairDixon finding similar (not same) words is a totally different task and requires more complex algorithm, maybe this will help you http://stackoverflow.com/questions/2344320/comparing-strings-with-tolerance – VladL May 26 '13 at 22:47
  • @VladL , it is definitely going to be complex . i will have to probably do the conversion after the space bar is pressed for this language –  May 26 '13 at 23:01
1

I think your best bet for this would be a text file that is loaded into memory when the application starts up. I would imagine you'd want to have a listbox created at runtime at the location of the textboxs current carrot locations (plus some x and y so the textbox is clearly visible above/below the listbox) and then you could have all possible options in the listbox for the user to click the correct answer. Is this the kind of thing you are looking for?

Here's a link to a dictionary text file you could use, although it would need some processing to only contain words:

http://www.gutenberg.org/files/29765/29765-8.txt

FraserOfSmeg
  • 1,128
  • 2
  • 23
  • 41
  • And what was the result? Too slow? It didn't look sleek enough? I can't really help any further if you don't give me more info. – FraserOfSmeg May 26 '13 at 22:06
  • i have tried that method where by I made another rich text box and added thext to it and made it ReadOnly . then when I type in the RichTextBox1 which is also ReadOnly (I input thex into RichTextBox1 by code) it then compared the word in RichTextBox1 to RichTextBox2 . but because they are both read only i have a few issues mainly the "ding" sound you get when you click a read only textbox . also I'm not very good at that method . I think the code I used for that method was a bit primitive –  May 26 '13 at 22:12
  • because i also want to use text replacement for other languages –  May 26 '13 at 22:36