I want to design spell checker, my task is to read all words one by one and search in a DataBase table if a word already exists in the table, do nothing if the word is not in database, highlight it if it is.
I have done this formula but I can't understand where is problem, since it does not work perfectly.
Dim lenoftxt As Integer
Dim i As Integer
Dim str As String
Dim tillword As String
tillword = ""
str = ""
i = 1
If Not RichTextBox1.Text = "" Then
lenoftxt = RichTextBox1.Text.Length
' MsgBox(lenoftxt)
For i = 1 To lenoftxt
str = Mid(RichTextBox1.Text, i, 1)
' MsgBox(str)
tillword = tillword & str
If str = " " Then
i = i + 1
tillword = Mid(tillword, 1, tillword.Length - 1)
' MsgBox(tillword)
romantranssql = "Select word from approved where word='" & tillword & "'"
MsgBox(romantranssql)
pth = My.Application.Info.DirectoryPath
romantransconn.ConnectionString = "Provider=Microsoft.ace.oledb.12.0; Data Source=" & pth & "\database.mdb; User Id=admin; Password=;"
romantransda = New OleDbDataAdapter(romantranssql, romantransconn)
romantransds = New DataSet
romantransda.Fill(romantransds, "DisplayCenterData")
romantransdt = romantransds.Tables("DisplayCenterData")
romantranscmb = New OleDbCommandBuilder(romantransda)
If Me.BindingContext(romantransdt).Count >= 1 Then
MsgBox("record found - " & tillword)
tillword = ""
End If
If Me.BindingContext(romantransdt).Count <= 0 Then
RichTextBox1.Select(i, tillword.Length)
RichTextBox1.SelectionColor = System.Drawing.Color.Red
tillword = ""
End If
End If
Next
End If
The method I'm using is adding characters one by one to the tillword
string and if a space is found I consider the word is complete and search it in DataBase table. If found I do nothing and if not found in the DataBase I highlight it.