Word Spell Checker : Word « Windows « VB.Net Tutorial

VB.Net Tutorial
1. Language Basics
2. Data Type
3. Operator
4. Statements
5. Date Time
6. Class Module
7. Development
8. Collections
9. Generics
10. Attributes
11. Event
12. Stream File
13. GUI
14. GUI Applications
15. 2D Graphics
16. I18N Internationlization
17. Reflection
18. Regular Expressions
19. Security
20. Socket Network
21. Thread
22. Windows
23. XML
24. Database ADO.net
25. Design Patterns
Microsoft Office Word 2007 Tutorial
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / C Sharp
C# / CSharp Tutorial
ASP.Net
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
PHP
Python
SQL Server / T-SQL
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial » Windows » Word 
22. 20. 6. Word Spell Checker
 

Imports System.Windows.Forms

public class WordSpellChecker
   public Shared Sub Main
        Application.Run(New Form1)
   End Sub
End class

Public Class Form1

    Dim objWordApp As Word.Application
    Dim objCorrectionsCollection As Word.SpellingSuggestions
    Dim objSpellCollection As Word.ProofreadingErrors

    Private Sub OpenWord()
        objWordApp = New Word.Application
    End Sub

    Private Sub CloseWord()
        objWordApp.Documents.Close(Word.WdSaveOptions.wdDoNotSaveChanges)
        objWordApp.Quit()
        objWordApp = Nothing
    End Sub

    Private Sub btnSpellCheckDoc_Click(ByVal sender As System.Object, ByVal e As System.EventArgsHandles btnSpellCheckDoc.Click

        Dim objRange As Word.Range
        Dim intWord As Integer
        Dim strNewWord As String

        Me.Text = "Starting Word ..."
        Call OpenWord()
        objWordApp.Documents.Add()

        Me.Text = "Checking words..."
        objRange = objWordApp.ActiveDocument.Range
        objRange.InsertAfter(TextBox1.Text)
        objSpellCollection = objRange.SpellingErrors

        If objSpellCollection.Count > Then
            ListBox1.Items.Clear()
            ListBox2.Items.Clear()
            For intWord = To objSpellCollection.Count
                strNewWord = objSpellCollection.Item(intWord).Text
                If ListBox1.FindStringExact(strNewWordThen
                    ListBox1.Items.Add(strNewWord)
                End If
            Next
        End If
        Me.Text = "WordSpellChecker"

    End Sub

    Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgsHandles Me.FormClosing
        Call CloseWord()
    End Sub

    Private Sub ListBox1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgsHandles ListBox1.SelectedIndexChanged

        Dim intWord As Integer

        objCorrectionsCollection = objWordApp.GetSpellingSuggestions(ListBox1.Text)
        ListBox2.Items.Clear()
        If objCorrectionsCollection.Count > Then
            For intWord = To objCorrectionsCollection.Count
                ListBox2.Items.Add(objCorrectionsCollection.Item(intWord).Name)
            Next
        Else
            ListBox2.Items.Add("No suggestions!")
        End If

    End Sub

    Private Sub btnReplaceWord_Click(ByVal sender As System.Object, ByVal e As System.EventArgsHandles btnReplaceWord.Click
        If ListBox1.SelectedIndex >= And ListBox2.SelectedIndex >= Then
            TextBox1.Text = Replace(TextBox1.Text, _
                ListBox1.SelectedItem, ListBox2.SelectedItem)
            ListBox1.Items.Remove(ListBox1.SelectedIndex)
            ListBox2.Items.Clear()
        End If
    End Sub
End Class
Partial Public Class Form1
    Inherits System.Windows.Forms.Form

    <System.Diagnostics.DebuggerNonUserCode()> _
    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

    End Sub

    'Form overrides dispose to clean up the component list.
    <System.Diagnostics.DebuggerNonUserCode()> _
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing AndAlso components IsNot Nothing Then
            components.Dispose()
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    <System.Diagnostics.DebuggerStepThrough()> _
    Private Sub InitializeComponent()
        Me.TextBox1 = New System.Windows.Forms.TextBox
        Me.btnSpellCheckDoc = New System.Windows.Forms.Button
        Me.btnReplaceWord = New System.Windows.Forms.Button
        Me.ListBox1 = New System.Windows.Forms.ListBox
        Me.ListBox2 = New System.Windows.Forms.ListBox
        Me.Label1 = New System.Windows.Forms.Label
        Me.Label2 = New System.Windows.Forms.Label
        Me.SuspendLayout()
        '
        'TextBox1
        '
        Me.TextBox1.Location = New System.Drawing.Point(109)
        Me.TextBox1.Multiline = True
        Me.TextBox1.Name = "TextBox1"
        Me.TextBox1.Size = New System.Drawing.Size(352192)
        Me.TextBox1.TabIndex = 0
        Me.TextBox1.Text = "This is some example text that contains misspelled words. For example, Visual Bas" & _
            "ci Espress."
        '
        'btnSpellCheckDoc
        '
        Me.btnSpellCheckDoc.Location = New System.Drawing.Point(3699)
        Me.btnSpellCheckDoc.Name = "btnSpellCheckDoc"
        Me.btnSpellCheckDoc.Size = New System.Drawing.Size(15823)
        Me.btnSpellCheckDoc.TabIndex = 3
        Me.btnSpellCheckDoc.Text = "SpellCheck Document"
        '
        'btnReplaceWord
        '
        Me.btnReplaceWord.Location = New System.Drawing.Point(369306)
        Me.btnReplaceWord.Name = "btnReplaceWord"
        Me.btnReplaceWord.Size = New System.Drawing.Size(15823)
        Me.btnReplaceWord.TabIndex = 4
        Me.btnReplaceWord.Text = "Replace Word"
        '
        'ListBox1
        '
        Me.ListBox1.FormattingEnabled = True
        Me.ListBox1.Location = New System.Drawing.Point(10232)
        Me.ListBox1.Margin = New System.Windows.Forms.Padding(3133)
        Me.ListBox1.Name = "ListBox1"
        Me.ListBox1.Size = New System.Drawing.Size(16895)
        Me.ListBox1.TabIndex = 1
        '
        'ListBox2
        '
        Me.ListBox2.FormattingEnabled = True
        Me.ListBox2.Location = New System.Drawing.Point(196232)
        Me.ListBox2.Margin = New System.Windows.Forms.Padding(3133)
        Me.ListBox2.Name = "ListBox2"
        Me.ListBox2.Size = New System.Drawing.Size(16695)
        Me.ListBox2.TabIndex = 2
        '
        'Label1
        '
        Me.Label1.AutoSize = True
        Me.Label1.Location = New System.Drawing.Point(10217)
        Me.Label1.Margin = New System.Windows.Forms.Padding(3330)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(9414)
        Me.Label1.TabIndex = 5
        Me.Label1.Text = "Misspelled words:"
        '
        'Label2
        '
        Me.Label2.AutoSize = True
        Me.Label2.Location = New System.Drawing.Point(196217)
        Me.Label2.Margin = New System.Windows.Forms.Padding(3330)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(9414)
        Me.Label2.TabIndex = 6
        Me.Label2.Text = "Alternative words:"
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(513)
        Me.ClientSize = New System.Drawing.Size(539342)
        Me.Controls.Add(Me.Label2)
        Me.Controls.Add(Me.Label1)
        Me.Controls.Add(Me.ListBox2)
        Me.Controls.Add(Me.ListBox1)
        Me.Controls.Add(Me.btnReplaceWord)
        Me.Controls.Add(Me.btnSpellCheckDoc)
        Me.Controls.Add(Me.TextBox1)
        Me.Name = "Form1"
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
        Me.Text = "WordSpellChecker"
        Me.ResumeLayout(False)
        Me.PerformLayout()

    End Sub
    Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
    Friend WithEvents btnSpellCheckDoc As System.Windows.Forms.Button
    Friend WithEvents btnReplaceWord As System.Windows.Forms.Button
    Friend WithEvents ListBox1 As System.Windows.Forms.ListBox
    Friend WithEvents ListBox2 As System.Windows.Forms.ListBox
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents Label2 As System.Windows.Forms.Label

End Class

        
22. 20. Word
22. 20. 1. Word Selection
22. 20. 2. Create Word document and print
22. 20. 3. Type Text
22. 20. 4. InsertAfter
22. 20. 5. Edit Word document
22. 20. 6. Word Spell Checker
w__w_w_.___j___a_v__a_2s_.___c__o_m | Contact Us
Copyright 2003 - 08 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.