0

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.

Jimi
  • 29,621
  • 8
  • 43
  • 61
fahad
  • 35
  • 6
  • For the Words extraction, you could use `string.Split()`. It will return all the Words in a text which are separated by a white space. Some more work required to separate the puctuation. `LINQ`'s `GroupBy()` can be use to group identical Words. `Regex.Match()` to find all the Words position within the Text. Something like this: [Color a Specific Word in every richtextbox line VB](https://stackoverflow.com/questions/49335419/color-a-specific-word-in-every-richtextbox-line-vb?answertab=active#tab-top). – Jimi Nov 07 '18 at 08:33
  • You say that it doesn't works perfectly, but you didn't mention what was the unexpected comportment. What is happening which was not as you wanted? – laancelot Nov 07 '18 at 23:14

1 Answers1

0

i Got Sollution with grace of God from my php programming its like this and works fine

 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)

            If str = "ا" Or str = "ب" Or str = "ٻ" Or str = "ڀ" Or str = "ت" Or str = "ٿ" Or str = "ٽ" Or str = "ٺ" Or str = "ث" Or str = "پ" Or str = "ج" Or str = "ڄ" Or str = "ڃ" Or str = "چ" Or str = "ڇ" Or str = "ح" Or str = "خ" Or str = "د" Or str = "ڏ" Or str = "ڌ" Or str = "ڊ" Or str = "ڍ" Or str = "ذ" Or str = "ر" Or str = "ڙ" Or str = "ز" Or str = "س" Or str = "ش" Or str = "ص" Or str = "ض" Or str = "ط" Or str = "ظ" Or str = "ع" Or str = "غ" Or str = "ف" Or str = "ڦ" Or str = "ق" Or str = "ڪ" Or str = "ک" Or str = "گ" Or str = "ڳ" Or str = "ڱ" Or str = "ل" Or str = "م" Or str = "ن" Or str = "ڻ" Or str = "و" Or str = "ه" Or str = "ھ" Or str = "ي" Or str = "ئ" Or str = "آ" Or str = "۾" Or str = "۽" Or str = "ِ" Or str = "َ" Or str = "ُ" Or str = "ى" Then



                tillword = tillword & str

            Else



                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
                    Dim a As Integer
                    a = tillword.Length + 1


                    RichTextBox1.Select(i - a, tillword.Length)
                    ' MsgBox(RichTextBox1.SelectedText & " selected text, not found and red")
                    RichTextBox1.SelectionColor = System.Drawing.Color.Red
                    MsgBox(RichTextBox1.SelectedText & "-" & i - a & "-" & tillword.Length)



                    ListBox1.Items.Add(tillword)

                    txtnormalword.Text = tillword

                    '    Button5_Click_1(sender, New System.EventArgs())



                    tillword = ""






                End If



            End If
        Next
    End If


    '   tillword = ""

put english alphabet on ur case instead of sindhi arabic alphabet as fallows

                If str = "ا" Or str = "ب" Or str = "ٻ" Or str = "ڀ" Or str = "ت" Or str = "ٿ" Or str = "ٽ" Or str = "ٺ" Or str = "ث" Or str = "پ" Or str = "ج" Or str = "ڄ" Or str = "ڃ" Or str = "چ" Or str = "ڇ" Or str = "ح" Or str = "خ" Or str = "د" Or str = "ڏ" Or str = "ڌ" Or str = "ڊ" Or str = "ڍ" Or str = "ذ" Or str = "ر" Or str = "ڙ" Or str = "ز" Or str = "س" Or str = "ش" Or str = "ص" Or str = "ض" Or str = "ط" Or str = "ظ" Or str = "ع" Or str = "غ" Or str = "ف" Or str = "ڦ" Or str = "ق" Or str = "ڪ" Or str = "ک" Or str = "گ" Or str = "ڳ" Or str = "ڱ" Or str = "ل" Or str = "م" Or str = "ن" Or str = "ڻ" Or str = "و" Or str = "ه" Or str = "ھ" Or str = "ي" Or str = "ئ" Or str = "آ" Or str = "۾" Or str = "۽" Or str = "ِ" Or str = "َ" Or str = "ُ" Or str = "ى" Then
fahad
  • 35
  • 6
  • Instead of checking `If ... Or ... Or ... Or ...` just check `If Char.IsLetter(str.Chars(0)) Then` - much shorter and should work with pretty much all languages. – Visual Vincent Nov 07 '18 at 17:44