Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- How to make a "Spell Checker" in Visual Basic 2008/2010
- -
- Requirements:
- - 1 TextBox
- - 1 Button > Text: Check
- - 1 Label > *** MAKE THE TEXT TO BLANK ***
- ==
- Codes: *** COPY AND PASTE THE CODES BETWEEN "PUBLIC CLASS FORM1" AND "END CLASS" ***
- ==
- Public Function OnlyCharacter(ByVal key As String) As Boolean
- If (key >= 65 And key <= 90) Or (key >= 97 And key <= 122) Or key = 8 Then
- OnlyCharacter = False
- Else
- OnlyCharacter = True
- End If
- End Function
- Private Function chkSplng(ByVal sTxt As String) As Boolean
- Dim spellCheker As New Object()
- spellCheker = CreateObject("Word.Application")
- chkSplng = spellCheker.CheckSpelling(sTxt)
- End Function
- Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
- e.Handled = OnlyCharacter(Asc(e.KeyChar))
- End Sub
- Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
- Dim Text As String
- On Error Resume Next
- Text = TextBox1.Text
- If Text = "" Then
- MsgBox("Type a text to check if the spelling is correct!", vbExclamation)
- Exit Sub
- End If
- If chkSplng(Text) = True Then
- Label1.ForeColor = Color.Green
- Label1.Text = "The Spelling is Correct!"
- Else
- Label1.ForeColor = Color.Red
- Label1.Text = "The Spelling is Incorrect!"
- End If
- Text = ""
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement