SpellCheck () Function

The spell check function is used to spell check a series of words. The text body containing the words is checked using the CheckTextBodyV2 operation of the spell checker's check.asmx web service. The results of the spell check come in the form of a DocumentSummary class provided by the web service. Within DocumentSummary, you will find an array of misspelled words and associated spelling suggestions. For each misspelled word found within the text block, a custom windows form named SpellCheckForm.vb displays the misspelled word and the suggested corrections. Within the windows form, the end user must either correct the misspelling manually or select one of the suggested corrections. After the user closes the form, the misspelled word is replaced by the corrected word within the text body. After all misspelled words are dealt with, the corrected text body is returned from the function to the calling procedure.

Below you will find the code for the SpellCheck function and a screen shot of the Windows form.

Private Function SpellCheck(ByVal TextBody As String) As String
        Dim spellchecker As New SpellCheckSvc.check
        Dim spellcheckresults As SpellCheckSvc.DocumentSummary
        Dim MisspelledWords() As SpellCheckSvc.Words

        spellcheckresults = spellchecker.CheckTextBodyV2(TextBody)

        If spellcheckresults.MisspelledWordCount > 0 Then
            MisspelledWords = spellcheckresults.MisspelledWord

            For x = 0 To MisspelledWords.Length - 1
                Dim MisspelledWord As String = MisspelledWords(x).word
                Dim Suggestions() As String = MisspelledWords(x).Suggestions

                Dim SpellCheckForm As New SpellCheckForm(MisspelledWord, Suggestions)
                SpellCheckForm.ShowDialog()

                Dim selectedword As String = SpellCheckForm.SelectedSuggestedWord
                If selectedword.Length > 0 Then
                    TextBody = Replace(TextBody, MisspelledWord, selectedword)
                End If
            Next
        End If

        Return TextBody

End Function

The SpellCheckForm.vb win form displayed above was added into the Blackbaud.CustomFx.FoodBank.Client project as part of the customization.