Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Spelling Check

Status
Not open for further replies.

cslawtom

MIS
Sep 3, 2001
161
HK
Hi All,

I would like to know whether I could include spelling check feature in my program or not.

Thanks in advance
 
Word SpellChecker Example
faq184-4258

Word SpellChecker example (Version 2)
faq184-4292

Word SpellChecker Example (Version 3)
faq184-4482

Slighthaze = NULL
craig1442@mchsi.com
"Whom computers would destroy, they must first drive mad." - Anon​
 
Hi Slighthaze,

I have tried the version 3. But I got a problem as below:

Click on the command:
IF EMPTY(ThisForm.Edit1.Value)
RETURN
ENDIF

oWord = CreateObject("word.application")

With oWord
.Documents.add
.Selection.TypeText(ThisForm.Edit1.Value)
.Visible = .T.
.Activedocument.CheckSpelling
.Selection.WholeStory
.Selection.Copy
.ActiveDocument.Close(0)

.Quit
EndWith

ThisForm.Edit1.Value = _ClipText

MESSAGEBOX("Spell Check Complete.")

_CLIPTEXT returns nothing

But if I place ThisForm.Edit1.Value = _ClipText in another command button. i.e. one command for check and one command for replace the value, it works OK.

Do you have any idea? Thanks.
 
I wonder if it is timing issue where the computer is working too fast. Try putting the following code just before the ThisForm.Edit1.Value = _ClipText


* make it wait 2 seconds
INKEY(2)

Jim Osieczonek
Delta Business Group, LLC
 
cslawtom

Here is "bits and pieces" or a spellcheck routine that now works perfectly. Credit to (Mike) mgagnon and other visfox tek-tips forum members who helped me out with this sometime ago.

Bear in mind this particular code spellchecks a memo field, stores it and returns it to the table. I think was an issue once where the spellcheck routine started but did not save the contents of that memo field when it had finished.
Good luck
KB

PUBLIC oform1
oform1=CREATEOBJECT("form1")
oform1.Show
RETURN

DEFINE CLASS form1 AS form
Height = 350
Width = 600
ShowWindow = 2
AutoCenter = .T.
BorderStyle = 1
Caption = "Word Spell Check"
MaxButton = .F.
MinButton = .F.
Movable = .F.
* Icon="crdfle04.ico"
Name = "Form1"

ADD OBJECT edttexttocheck AS editbox WITH ;
Height = 280, ;
Left = 20, ;
Top = 20, ;
Width = 560, ;
Name = "edtTextToCheck"

ADD OBJECT cmdcheckspelling AS commandbutton WITH ;
Top = 312, ;
Left = 130, ;
Height = 27, ;
Width = 149, ;
Caption = &quot;\<Spell Check&quot;, ;
Name = &quot;cmdCheckSpelling&quot;

* Thi has been added as an additional command button

ADD OBJECT cmdsaveafter AS commandbutton WITH ;
Top = 312, ;
Left = 300, ;
Height = 27, ;
Width = 149, ;
Caption = &quot;\<Save & Exit&quot;, ;
Name = &quot;cmdsaveafter&quot;

PROCEDURE findword

LOCAL lcPath, lcResult, lcFileName, llRetVal, ;
lcCurDir, lnFileHand, lcWordPath

lcPath = SPACE(0)
lcResult = SPACE(128)
llRetVal = .F.
lcCurDir = SUBSTR(SYS(16,0),ATC([ ],SYS(16,0),2)+1)
lcCurDir = SUBSTR(lcCurDir,1,RAT([\],lcCurDir))

lcFileName = lcCurDir + SYS(3) + [.doc]

lnFileHand = FCREATE(lcFileName,0)
= FCLOSE(lnFileHand)

DECLARE INTEGER FindExecutable IN shell32 STRING @lcFilename, ;
STRING @lcPath , STRING @lcResult

IF FindExecutable(@lcFileName, @lcPath, @lcResult) > 32
lcWordPath = UPPER(SUBSTR(lcResult,1,LEN(ALLTR(lcResult))-1))
IF [WINWORD] $ lcWordPath
llRetVal = .T.
ENDIF
ENDIF
ERASE (lcFileName)
RETURN llRetVal
ENDPROC

PROCEDURE Destroy
IF TYPE([goWord]) = [O]
IF TYPE([goWordDoc]) = [O]
goWordDoc.SAVED = .T.
goWordDoc.CLOSE
ENDIF
goWord.QUIT
ENDIF
RELEASE goWord, goWordDoc
ENDPROC

**************
PROCEDURE Init
**************

CLOSE DATABASES

* *****************************************************************************
* USE YOURTABLE && You Need To Add Your Table Here

* USE TTTD && This Is Mine!
* GO 1 && Which Ever Record You want To Spell Check
* *****************************************************************************

STORE TRIM(QUESTION) TO mquestion && This Is Your Memo Field In Your Table

THIS.edtTextToCheck.VALUE = mquestion && Memo Field
ENDPROC

PROCEDURE cmdcheckspelling.Click

IF TYPE([goWord]) # [O] && Check if you have already instantiated Word

IF !THISFORM.FindWord() && You don't have Word up, so let's locate it.
MESSAGEBOX([Microsoft Word is either not installed or is incorrectly registered.], + ;
0,[Word Start-Up Failed])
RETURN .F.
ENDIF

WITH THISFORM
.cmdCheckSpelling.MOUSEPOINTER = 11
.edtTextToCheck.MOUSEPOINTER = 11
.MOUSEPOINTER = 11
ENDWITH

PUBLIC goWord, goWordDoc && Public vars for Word and Document1 in Word.
goWord = CREATEOBJECT([WORD.APPLICATION]) && Create Word
WITH goWord
.WINDOWSTATE= 0 && wdWindowStateNormal (needs to be Normal before you can move it)
.MOVE(1000,1000) && Move the window out of view
goWordDoc = .Documents.ADD
ENDWITH

WITH THISFORM
.cmdCheckSpelling.MOUSEPOINTER = 0
.edtTextToCheck.MOUSEPOINTER = 0
.MOUSEPOINTER = 0
ENDWITH

ENDIF

WITH goWordDoc
.Content.TEXT = ALLTRIM(THISFORM.edtTextToCheck.VALUE)
.ACTIVATE
IF .SpellingErrors.COUNT > 0
.CHECKSPELLING
ELSE
=MESSAGEBOX([Spell check complete. No errors found],0+48+0,[Spell Check])
ENDIF
goWord.VISIBLE = .F.
THISFORM.edtTextToCheck.VALUE = .Content.TEXT
ENDWITH
=MESSAGEBOX(&quot;Spell Check Complete&quot;+space(10),0+48+0,&quot;System Message&quot;)
ENDPROC

PROCEDURE cmdsaveafter.Click
GO mrecno
REPLACE QUESTION with this.parent.edtTextToCheck.value
CLOSE DATABASES
THISFORM.RELEASE

ENDDEFINE



Alone we can do so little, together we can do so much
 
Hi Lee,

I have tried your program. It works well.
Meanwhile I have used SlightHaze's coding in my program.

Thks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top