Advertisement
NiCz

How to Make a Spell Checker

Oct 15th, 2012
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 1.57 KB | None | 0 0
  1. How to make a "Spell Checker" in Visual Basic 2008/2010
  2. -
  3. Requirements:
  4. - 1 TextBox
  5. - 1 Button > Text: Check
  6. - 1 Label > *** MAKE THE TEXT TO BLANK ***
  7. ==
  8. Codes: *** COPY AND PASTE THE CODES BETWEEN "PUBLIC CLASS FORM1" AND "END CLASS" ***
  9. ==
  10.  Public Function OnlyCharacter(ByVal key As String) As Boolean
  11.         If (key >= 65 And key <= 90) Or (key >= 97 And key <= 122) Or key = 8 Then
  12.             OnlyCharacter = False
  13.  
  14.         Else
  15.             OnlyCharacter = True
  16.         End If
  17.     End Function
  18.     Private Function chkSplng(ByVal sTxt As String) As Boolean
  19.         Dim spellCheker As New Object()
  20.         spellCheker = CreateObject("Word.Application")
  21.         chkSplng = spellCheker.CheckSpelling(sTxt)
  22.     End Function
  23.  
  24.     Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
  25.         e.Handled = OnlyCharacter(Asc(e.KeyChar))
  26.     End Sub
  27.  
  28.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  29.         Dim Text As String
  30.         On Error Resume Next
  31.         Text = TextBox1.Text
  32.  
  33.         If Text = "" Then
  34.             MsgBox("Type a text to check if the spelling is correct!", vbExclamation)
  35.             Exit Sub
  36.         End If
  37.  
  38.         If chkSplng(Text) = True Then
  39.             Label1.ForeColor = Color.Green
  40.             Label1.Text = "The Spelling is Correct!"
  41.         Else
  42.             Label1.ForeColor = Color.Red
  43.             Label1.Text = "The Spelling is Incorrect!"
  44.         End If
  45.  
  46.         Text = ""
  47.     End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement