Zur Startseite

JRSpellChecker

Zur Homepage

How to integrate JRSpell in your application:

do the following steps.

1.

Load JRSpell.ocx to your programming environment:

Add JRSpell.ocx to your Toolbox, then drag them to your form.

Alternatively set an reference to JRSpell.ocx and bind the COMObjekt as follows.

  Set JRSpell1 = CreateObject("JRSpellAx.JRSpell")

to bind the control about the ClassID use this one for the actual Version of JRSpell.
      CLSID:C631C56C-2600-4EF4-B20D-E92BA360A328

   

Note! a project with ActiveX Controls can not be compiled as 64bit. If you used JRSpell in Visual Studio 2008 or higher, be sure to set the destination system as X86. (Menu "create / Configurationmanager")

2.

Set properties:


Set in the settings dialogue or in the start code of your form your settings. You can change all settings at any time in the code.

    JRSpell1.UILanguage = English
    JRSpell1.SelectionMethod = Sel_BackColor
    JRSpell1.SelectionColor = vbRed

UILanguage: JRSpell has several internal dialogs, choose of the following language.

    english = 0
    german = 1
    spain = 2
    french = 3
    italian = 4
    netherland = 5

SelectionMethod: the following methods are available.

    Sel_BackColor = 0   (RTFControl, TX-Textcontrol)
    Sel_DoubleUnderline = 1   (RTFControl, TX-Textcontrol)
    Sel_TwigglyUnderline = 2 (TX-Textcontrol ab V8.0)
    Sel_Forecolor = 3 (RTFControl, TX-Textcontrol)
    Sel_nothing = 10 (All)

SelectionColor: Color value for the selection.

Switch off one ore more of the following settings. All of them are active by default.

    JRSpell1.IgnoreUppercaseWords     (e.g IFA, NEWSLETTER)
    JRSpell1.IgnoreMixedCaseLetterWords (e.g NewEconomy)
    JRSpell1.IgnoreURL (e.g www.myurl.com http://myurl.com me@mail.com)
    JRSpell1.IgnoreWordsWithNumbers (
    e.g V3.2, Ready2go)

3.

Load a JRSpell dictionary :

JRSpell shipped with dictionary's in English and German.
To load a dictionary will take up to 3s.
Note the following:

    1. load the dictionary one time for example in the main or Form_Load procedure of your application.
    2.
    wait for the WordBookLoadEnd event before spelling.
    3. If you call the OpenSpellcheckdialog, wait again for the WordBookLoadEnd event.

To load the shipped US-English dictionary set

    JRSpell1.WordBookName = "en_us.jsp"

    en_gb.jsp includes the GB dictionary.
    en_us.jsp includes the US dictionary.
    de_de20062.jsp includes the German dictionary

    de_de.jsp
    includes the German dictionary with old spelling rules.

then call

    JRSpell1.LoadWordbook(LokalWordBook)
              (LokalWordBook = 0).

JRSpell1.LoadWordbook returns True if the file was found, otherwise False.
If the return value is false, then popup a message or block all spelling actions.

If the dictionary file was found, it will be loading in the background and the WordBookLoadend event is raised.

Under www.jrsoft.de you can load more than 15 other dictionary languages..
To add a dictionary you can copy it manually to the JRSpell.ocx path or by the WordBookDialog
.
By default all the dictionary's saved in the install path
of JRSpell.ocx (commonappdata\JRSpell).
If you want to write a routine for copy the dictionary's, use JRSpell.Get
CurrentPath to get the destination path.
You can copy additional dictionary's with your setup routine too. Have a look to the SETUP folder in the JRSpell install path.

Alternatively use any path to read dictionary's by set the WordBookPath before LoadWordbook is called.

4.

OR load a MS-Word dictionary:

JRSpell can load instead of the local JRSpell dictionary the MS-Word dictionary.
All the spelling code in your application are the same.


To load the MS-Word dictionary set

    JRSpell1.WordBookName = ""

then call

      JRSpell1.LoadWordbook(WordWordBook)
              (WordWordBook = 1).

JRSpell1.LoadWordbook returns True if the Word-Dictionary was found, otherwise False.
If the return value is false, then popup a message or block all spelling actions.

If the dictionary file was found, it will be loading in the background and the WordBookLoadend event is raised.

Under normal conditions you don't know, do your users has installed Word or not.
The following routine is a good solution for this problem.

    JRSpell1.WordBookName = ""  
    If JRSpell1.LoadWordbook(WordWordBook) = False Then
        JRSpell1.WordBookName = "en_us.jsp"
        JRSpell1.LoadWordbook(LokalWordBook)
    End If

5.

Spelling a word / string :

SpellCheckString is the simplest way to spell a single word or a complete string.
The function needs the parameters "Word,CheckStartPosition,CheckEndPosition" and returns the spelling of the word. Settings like

    JRSpell1.IgnoreUppercaseWords     (e.g IFA, NEWSLETTER)
    JRSpell1.IgnoreMixedCaseLetterWords (
    e.g NewEconomy)
    JRSpell1.IgnoreURL (e.g www.myurl.com http://myurl.com me@mail.com)
    JRSpell1.IgnoreWordsWithNumbers (e.g V3.2, Ready2go)
    JRSpell1.
    CheckGrammar

has affect to the spelling..

    CurrentTestpos&=0
    JRSpell1.SpellCheckString("Hello", CurrentTestpos,
    len("Hello"))

You can interpret the spelling result of SpellCheckString in different ways.

    1. CurrentTestpos returns the start position of the first misspelled word, otherwise -1
    2. Every spelled word raises the SpellCheckWord event. You might get the result there.
    3. Every misspelling is setting several infos in JRSpell.SpellInfo_ , you can use information like JRSpell1.SpellInfo_MisspelledWord
    <>"".

To spell a complete string for example you can do as follows.


    teststring$ = "this text will be tested"
    'the jrspell_spellcheckedword event returns the incorrect word
    'teststart returns the first characterpos of a incorrect word. returns -1 if no incorrect word was found
    'testend
    returns the last characterpos of a incorrect word
    'check the complete string
    teststart& = 0
    testend& =
    Len(teststring$)

    do
    x = JRSpell1.SpellCheckString(
    teststring$, teststart&, testend&)
    'if any
    incorrect word was found, then search for the next one
    If JRSpell1.SpellInfo_MisspelledWord
    <> "" Then
        MsgBox "
    -->> " + JRSpell1.SpellInfo_MisspelledWord
       
    teststart& = testend&
     
    End If
    loop
    while teststart&<>-1

6.

Correct a single word with dialog:

OpenSpellCheckDialog opens a dialog to correct a single word. It returns False if the user choose the close button, otherwise True.


Before open the dialogue set some flags for customize

    'set options for the correction dialogue
    JRSpell1.CorrectionDialogActions = SearchNextAfterClickList + ShowAddButtonLokalWordBook + ShowAddButtonMSWord + ShowChangeButton + ShowIgnoreAllButton + ShowChangeAllButton

        possible flag values are
        ShowChangeButton = 1
        ShowAddButtonMSWord = 2
        ShowAddButtonLokalWordBook = 4
        ShowIgnoreAllButton = 8
        SearchNextAfterClickList = 16
        ShowChangeAllButton = 32
        UseSpellAsyouType = 128 (nicht relevant)
        UseLeftMouseButtonSpell = 256 (nicht relevant)
        ShowModalForm = 512

then call the function

    Abbruch = JRSpell1.OpenSpellCheckDialog("Hello")

If the user choose a other word or correct them manually the ChangeWord event is raised. You have to change the word in your string manually. The following informations are helpful at this time.

    JRSpell1.SpellInfo_MisspelledWord -> the spelled word
    JRSpell1.SpellInfo_SelektedWord -> the user has choose or correct to this word
    JRSpell1.SpellInfo_StartposOffset -> length different old/new word

For advanced functions use the following events:
AddWordToWordbook:

If the user adds a word to the dictionary by the open dialog, this event is raised.

Autocorrection:
not supported in this function

7.

Check and correct a word / string with a Dialog:

SpellCheckStringWithDialog opens a correction dialog for spelling and correct the text. It returns the spelled text. The dialog supports Popup-Correction, SpellAsYouType and AutoCorrection.

Before open the dialogue set some flags for customize

    'set options for the correction dialogue
    JRSpell1.CorrectionDialogActions = UseLeftMouseButtonSpell + UseSpellAsyouType + SearchNextAfterClickList + ShowAddButtonLokalWordBook + ShowAddButtonMSWord + ShowChangeButton + ShowIgnoreAllButton + ShowChangeAllButton

        possible flags
        ShowChangeButton = 1
        ShowAddButtonMSWord = 2
        ShowAddButtonLokalWordBook = 4
        ShowIgnoreAllButton = 8
        SearchNextAfterClickList = 16
        ShowChangeAllButton = 32
        UseSpellAsyouType = 128
        UseLeftMouseButtonSpell = 256
        ShowModalForm = 512

then call the function

    spelledtext = JRSpell1.SpellCheckStringWithDialog("Check this string")

For advanced functions use the following events:
AddWordToWordbook:

If the user adds a word to the dictionary by the open dialog, this event is raised.


AutoCorrection:
If you have not allways active the autocorrection function but you want to use it for this call, then activate it with

    JRSpell1.AutoCorrectionOn

and deactivate it after the function is called with

    JRSpell1.AutoCorrectionOff

8.

Check a Document :

SpellCheckDocument very fast checking of a document in use of the Window-Handle. The checked control must be based on a Textbox, RTF-Control, NetRtf-Control or the TX-Textcontrol.
At the RTF-Control or the TX-Textcontrol the misspelled words will be marked.
Every spelled word is raising the SpellCheckWord event.
If the spelling has done the DocumentSpellChecked event is fired.
When
AutoCorrection is on, misspelled words will be replaced if the misspelled word is in the AutoCorrectionList.

Set a SelectionMethod if need

    'not relevant in use with a Textbox .
    JRSpell1.SelectionMethod = Sel_BackColor
    JRSpell1.SelectionColor = vbRed (any color number)

then call the function

    JRSpell1.SpellCheckDocument MyControl.hWnd, Rtf_Control
        possible bind values.
        Rtf_Control = 1
        Text_Box = 2
        TX_Textcontroll = 3
        NetRtf_Control = 11

AutoCorrection:
If you have not allways active the autocorrection function but you want to use it for this call, then activate it with

    JRSpell1.AutoCorrectionOn

and deactivate it after the function is called with

JRSpell1.AutoCorrectionOff

The AutoCorrection replaces misspelled words in use of the ChangeWord event. In this routine you have to replace the always selected word with the new one.

Private Sub JRSpell1_ChangeWord(newword As String)
    mycontrol.SelText =
newword
End Sub

9.

Check selected text :

SpellCheckSelText same as SpellCheckDocument, is checking only selected text and calls the SelectedTextSpellChecked event.

10.

Correct a Document :

SpellCheckWithDialog very fast checking of a document in use of the Window-Handle. The checked control must be based on a Textbox, RTF-Control, NetRtf-Control or the TX-Textcontrol.

On every misspelled word a dialog for correction will be opened.
When AutoCorrection
is on, misspelled words will be replaced if the misspelled word is in the AutoCorrectionList.

Before open the dialogue set some flags for customize

    JRSpell1.CorrectionDialogActions = SearchNextAfterClickList + ShowAddButtonLokalWordBook + ShowAddButtonMSWord + ShowChangeButton + ShowIgnoreAllButton + ShowChangeAllButton

      possible flags
      ShowChangeButton = 1
      ShowAddButtonMSWord = 2
      ShowAddButtonLokalWordBook = 4
      ShowIgnoreAllButton = 8
      SearchNextAfterClickList = 16
      ShowChangeAllButton = 32
      UseSpellAsyouType = 128
      UseLeftMouseButtonSpell = 256
      ShowModalForm = 512

then call the function

    JRSpell1.SpellCheckWithDialog mycontrol.hWnd, 0, Rtf_Control

      possible bind values.
      Rtf_Control = 1
      Text_Box = 2
      TX_Textcontroll = 3
      NetRtf_Control = 11

If the user has correct a word the ChangeWord event is fired. In this routine you have to replace the always selected word with the new one.

    Private Sub JRSpell1_ChangeWord(newword As String)
        mycontrol.SelText =
    newword
    End Sub

If the user cancels the spelling, or the last word was checked the SpellCheckWithDialogEnd event is fired.

For advanced functions use the following events:
SpellCheckWord:
Every spelled word raises the SpellCheckWord event.

AddWordToWordbook:
If the user adds a word to the dictionary by the open dialog, this event is raised.

ScollIntoPos und SpellCheckNextSelectedWord:
If a misspelled word was found the correction dialog will be opened.
JRSpell marls the misspelled word and fires the ScollIntoPos event. (For own controls you can adjust here the scroll position if needed.)
Then JRSpell fires the SpellCheckNextSelectedWord event. At this time you can read the following SpellInfos
Weitere Infos können an dieser Stelle durch Auswerten von

    JRSpell1.SpellInfo_MisspelledWord
    JRSpell1.SpellInfo_SelStartpos
    JRSpell1.SpellInfo_SelLength

AutoCorrection:
If you have not allways active the autocorrection function but you want to use it for this call, then activate it with

    JRSpell1.AutoCorrectionOn

and deactivate it after the function is called with

JRSpell1.AutoCorrectionOff


11.

Marking / autocorrection while typing (SpellAsYouType ):

SpellCheckLastInput returns in use of the Window-Handle information of the last typed word.
The checked control must be based on a Textbox, RTF-Control, NetRtf-Control or the TX-Textcontrol.
Misspelled words will be marked (not TextBox) .
When
AutoCorrection is !@on, misspelled words will be replaced if the misspelled word is in the AutoCorrectionList.

Normally SpellCheckLastInput is used in the KeyUp event of the control and is called only, when a complete word is typed. We can figure out this by check if the last key space, input, point, comma or several of the function keys.

A SpellAsYouType function in the KeyUp Event can look like the following code (be free to use other keycodes for your own routine).

    Select Case KeyCode
     
    Case 32, 13, 40, 37, 38, 39, 188, 189, 190
      'space,input,down arrow,left arrow,up arrow,right arrow,comma,-,.,

only if one of these keys are pressed SpellChackLastInput will be called.

If you didn't set a SelectionMethod do this before

    'Bei der Textbox wirkt sich diese Einstellung nicht aus.
    JRSpell1.SelectionMethod = Sel_BackColor
    JRSpell1.SelectionColor = vbRed

    oldsel = mycontrol.SelStart

then call the function

    SpellResult = JRSpell1.SpellCheckLastInput(mycontrol.hWnd, Rtf_Control)

      possible bind values.
      Rtf_Control = 1
      Text_Box = 2
      TX_Textcontroll = 3
      NetRtf_Control = 11

Note:
On the Textbox we don't have any marking function, so for example we can do a beep or flickering the window with other color if the SpellResult is False.

For advanced functions use the following events:
Für Erweiterte Auswertungen / Funktionen stehen folgende Events zur Verfügung:
TextSpellChecked:
Will be fired when Spellchecklastinput has done.
SpellCheckWord:
Spellchecklastinput is checking the current word and the word before and after this, so SpellCheckWord will be fired 3 times.

AutoCorrection:
If you have not allways active the autocorrection function but you want to use it for this call, then activate it with

    JRSpell1.AutoCorrectionOn

and deactivate it after the function is called with

JRSpell1.AutoCorrectionOff

The AutoCorrection replaces misspelled words in use of the ChangeWord event. In this routine you have to replace the always selected word with the new one.

Private Sub JRSpell1_ChangeWord(newword As String)
    mycontrol.SelText =
newword
End Sub

12.

Popup Correction while typing (Advanced SpellAsYouType ):

PopupCharPos is spelling the word at a given cursor position in use of the Window-Handle.
The checked control must be based on a Textbox, RTF-Control, NetRtf-Control or the TX-Textcontrol.
If the word is misspelled JRSpell opens a PopupMenu with suggestions.

As an enhancement of the SpellAsYouType function before, we can integrate a PopupCorrection as follows.

In my example the PopupCharPos will be called only if the last typed word was misspelled and its a different word as at the last popup.

then call the function

        JRSpell1.PopupCharPos mycontrol.SelStart, mycontrol.hWnd, Rtf_Control

        possible bind values.
        Rtf_Control = 1
        Text_Box = 2
        TX_Textcontroll = 3
        NetRtf_Control = 11

If the user choose a word with a other length from the PopupMenu we have to offset this value to the current cursor position. The Information you need is in the SpellInfo_StartposOffset.

        mycontrol.SelStart = oldsel + JRSpell1.SpellInfo_StartposOffset
       
    mycontrol.SetFocus
       
    Lastcheckedword = JRSpell1.SpellCheckLastInput_GetWord

    End If

If the user has correct a word the ChangeWord event is fired. In this routine you have to replace the always selected word with the new one.

    Private Sub JRSpell1_ChangeWord(newword As String)
        mycontrol.SelText =
    newword
    End Sub

For advanced functions use the following events:
AddWordToWordbook:

If the user adds a word to the dictionary by the open dialog, this event is raised.

13.

Popup Correction by click on a word :

PopupMousePos is spelling the word on a given mouse position in use of the Window-Handle. The checked control must be based on a Textbox, RTF-Control, NetRtf-Control or the TX-Textcontrol.
If the word is misspelled JRSpell opens a PopupMenu with suggestions.

Normally PopupMousepos is called in the MouseDown event of the control in use of the button value (left,right).

    If Button = 2 Then

then call the function

      JRSpell1.PopupMousePos x, y, mycontrol.hWnd, Rtf_Control

        possible bind values.
        Rtf_Control = 1
        Text_Box = 2
        TX_Textcontroll = 3
        NetRtf_Control = 11

If the user has correct a word the ChangeWord event is fired. In this routine you have to replace the always selected word with the new one.

    Private Sub JRSpell1_ChangeWord(newword As String)
        mycontrol.SelText =
    newword
    End Sub

For advanced functions use the following events:
AddWordToWordbook:

If the user adds a word to the dictionary by the open dialog, this event is raised.

Note:
PopupMousePos is not usable with the TX-Textcontrol. Up from V9 use the PopupCharPos
as follows

    charpos = TXTextControl1.InputPosFromPoint(x, y)
    JRSpell1.PopupCharPos
charpos, TXTextControl1.hWnd, TX_Textcontroll

14.

Correction Dialog by click on a word :

MisspelledWordFromMousePos is spelling the word on a given mouse position in use of the Window-Handle. The checked control must be based on a Textbox, RTF-Control, NetRtf-Control or the TX-Textcontrol.
This function returns the misspelled word.

Normally MisspelledWordfromMousepos is called in the MouseDown event of the control in use of the button (left, right).

    If Button = 1 Then

then call the function

    MisspelledWord = JRSpell1.MisspelledWordFromMousePos(x, y, mycontrol.hWnd, Rtf_Control)  

        possible bind values.
        Rtf_Control = 1
        Text_Box = 2
        TX_Textcontroll = 3
        NetRtf_Control = 11

if the function returns a value <> "" we open a correction dialog with the misspelled word

    If MisspelledWord <> "" Then
          JRSpell1.OpenSpellCheckDialog MisspelledWord
    End If

If the user has correct a word the ChangeWord event is fired. In this routine you have to replace the always selected word with the new one.

    Private Sub JRSpell1_ChangeWord(newword As String)
        mycontrol.SelText =
    newword
    End Sub

For advanced functions use the following events:
AddWordToWordbook:

If the user adds a word to the dictionary by the open dialog, this event is raised.

Hinweis:
MisspelledWordFromMousePos is not usable with the TX-Textcontrol. Up from V9 use MisspelledWordFromCharPos
as follows

    charpos = TXTextControl1.InputPosFromPoint(x, y)
    MisspelledWord = JRSpell1.MisspelledWordFromCharPos(
    charpos, TXTextControl1.hWnd, TX_Textcontroll)

15.

How to edit the autocorrection entries:

OpenWordBookDialog you or your users can edit the autocorrection list with the internal dialog.
To open the autocorrection dialog you have first to open the WordBookDialog.

For this case you can customize the WordBookDialog with some flags.

    JRSpell1.DictionaryDialogActions = HideAddDictionaryButton + DisableWordbookList + AllowEditAutoCorrection

      possible flags:
      AllowEnableMSWordDictionary = 1
      AllowEnableLokalDictionary = 2
      AllowEditUserDictionary = 4
      AllowEditAutoCorrection = 8
      DisableWordbookList = 16
      HideAddDictionaryButton = 32

then call the function

    JRSpell1.OpenWordBookDialog

You can manipulate the list with a own dialog and GetAutoCorrPath, GetAutoCorrList, SetAutoCorrList too.