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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Word SpellChecker Example

COM and Automation

Word SpellChecker Example

by  craigsboyd  Posted    (Edited  )
Slighthaze = [color blue]NULL[/color]

[img http://www.sweetpotatosoftware.com/ttimages/wordspell.gif]

The following is a good working example of how to use Microsoft Word's SpellChecker (CheckSpelling method of the document object).

Code:
PUBLIC oForm
oForm = createobject("clsspellcheck")
oForm.show()

DEFINE CLASS clsspellcheck AS form
	Autocenter = .T.
    Top = 0
    Left = 0
    Height = 493
    Width = 375
    DoCreate = .T.
    Caption = "WORD SPELLCHECKER"
    Name = "Form1"

    ADD OBJECT edit1 AS editbox WITH ;
        Height = 372, ;
        Left = 12, ;
        TabIndex = 2, ;
        Top = 84, ;
        Width = 348, ;
        ControlSource = "", ;
        Name = "Edit1"

    ADD OBJECT command1 AS commandbutton WITH ;
        Top = 48, ;
        Left = 276, ;
        Height = 27, ;
        Width = 84, ;
        Caption = "Spell Check", ;
        TabIndex = 1, ;
        Name = "Command1"

    ADD OBJECT label1 AS label WITH ;
        AutoSize = .T., ;
        BackStyle = 0, ;
        Caption = "Double-click inside Editbox or click Spell Check button", ;
        Height = 17, ;
        Left = 38, ;
        Top = 462, ;
        Width = 297, ;
        TabIndex = 5, ;
        ForeColor = RGB(0,0,255), ;
        Name = "Label1"

    ADD OBJECT label3 AS label WITH ;
        WordWrap = .T., ;
        BackStyle = 0, ;
        Caption = "Special thanks and credit to http://www.foxite.com/archives/0000020310.htm", ;
        Height = 37, ;
        Left = 12, ;
        Top = 47, ;
        Width = 264, ;
        TabIndex = 7, ;
        Name = "Label3"

    PROCEDURE findword
        LOCAL lcPath, lcResult, lcFileName, lcRetVal, lcCurdir, lnHandle, llRetVal
        lcPath = space(0)
        lcResult = space(255)
        llRetVal = .F.
        lcFileName = ADDBS(FullPath( Curdir()))+sys(3)+[.doc]
        lnhandle = fcreate(lcFileName,0)
        fclose(lnHandle)
        DECLARE INTEGER FindExecutable in shell32 string @lcFileName, string @lcPath, string @lcResult
        IF FindExecutable( @lcFileName, @lcpath, @lcResult) > 32

           IF [WINWORD] $ Upper(lcResult)
              llRetVal = .T.
           ENDIF
        ENDIF 
        erase lcFileName
        return llRetVal
    ENDPROC

    PROCEDURE Init
        LOCAL cString
        cString = "On the Product Download page, we haave updated our VFPCOM utility " + ;
                "to fully support Visual FoxPro 8.0. It has the same feetures and functionality " + ;
                "as the Visual FoxPro 7.0 version, but is now fully compatible with " + ;
                "Visual FoxPro 8.0. The VFPCOM utility allows you to extend Visual " + ;
                "FoxPro interoperability with other COM and ADO components. This utility " + ;
                "is a COM server that provides additional functionality when you use ADO " + ;
                "and access COM events with your Visual FoxPro 8.0 applications." + CHR(13) + ;
                "As I mentioned in my last letter, Microsoft has reeleased Visual FoxPro 8.0. " + ;
                "We are now busy working on Service Pack 1 (SP1) for Visual FoxPro 8.0. SP1 " + ;
                "for Visual FoxPro 8.0 is in beta now. I said that SP1 for Visual FoxPro 8.0 " + ;
                "would be released sometime in Setpember 2003 online for free download. " + ;
                "In our efforts to ensure quality and stability, it appears we will complete " + ;
                "SP1 the last week of September, which means it will actually be available " + ;
                "online for free download in early October." + CHR(13) + ;
                "Communities make it possible to get answers to your technical questions " + ;
                "concerning Visual FoxPro 8.0. You'll save time by tapping into a community " + ;
                "of peers who are building applications similar to yours. In addition, we've " + ;
                "collected technical support options and information on training and events. " + ;
                "And it's all free. For a great resource reference for related Visual FoxPro " + ;
                "community resources, refer to the Visual FoxPro Community Resource listings."

        thisform.edit1.Value = cString
    ENDPROC

    PROCEDURE edit1.DblClick
        LOCAL loWord, lnOldMousePointer
        lnOldMousePointer = this.Mousepointer
        this.Mousepointer = 11
        IF DODEFAULT()
           IF NOT thisform.FindWord()
              Messagebox("Word not installed on this machine...",48,_screen.caption)
              return .F.
           ELSE
              WAIT WINDOW NOWAIT "Spellchecking starts..."+CHR(13)+;
              " Please wait"
              IF VARTYPE( loWord ) <> 'O'
                 loWord = CREATEOBJECT('word.application')
              ENDIF
              IF VARTYPE ( loWord ) = "O"
                 loword.windowstate = 0
                 loWord.move(1000,1000)
                 loWord.documents.ADD()
                 WITH loWord
                    .documents(1).content = this.VALUE
                    WAIT WINDOW NOWAIT "Spellchecking has started..."+CHR(13)+;
                    " Please wait"
                    .documents(1).CheckSpelling()
                    .SELECTION.WholeStory
                    IF .selection.text <> this.VALUE
                       WAIT WINDOW NOWAIT "Spellchecking finished"+CHR(13)+;
                       "Your text will be replaced"
                       this.VALUE = .SELECTION.TEXT
                       REPLACE (this.CONTROLSOURCE) WITH (this.VALUE)
                    ELSE
                       WAIT WINDOW NOWAIT "Spellchecking finished"+CHR(13)+;
                       " No typos found"
                    ENDIF
                    .documents(1).CLOSE(.F.)
                    .QUIT
                 ENDWITH
                 loWord = .NULL.
                 RELEASE loWord
              ELSE
                 MESSAGEBOX("Sorry, I can not start Word",48,_SCREEN.CAPTION)
                 RETURN .F.
              ENDIF
              WAIT CLEAR
           ENDIF
        ENDIF
    ENDPROC

    PROCEDURE command1.Click
        thisform.edit1.DblClick()
    ENDPROC

ENDDEFINE
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top