*** i moved to my own blog site so to check on my future posts, please go to www.junblogs.com  ***

i woke up very early today at 2:30 am because i have to drop my nephew and my wife on my nephew's school for their field trip in mall of asia and enchanted kingdom.  i was back at our house after 45 minutes and then i realize i can no longer go back to sleep.  worse is i am not in the mood to watch cable fearing i will wake up my mom due to the tv sound and i don't want to do that as she is dead tired preparing last night things for her grandson.  i am likewise not in the mood to play any games or read paperbacks.  so i decided instead to open up those small notes i still haven't transferred to my cataloging software which i have also not yet read.  and i opened up one that seems interesting, i.e., "putting foxspell checker to work" by mike lewis.  sadly unlike most of his notes, this one did not show the hows.

intrigued, i performed a search in my mass storage to see if i have saved more something relating to spelling and i found another by slighthaze posted in tektips with this note: "special thanks and credit to http://www.foxite.com/archives/0000020310.htm.  his sample uses:


so that made me wonder since i have been playing these days with an rtf control and automation, why not see if i can implement it there too?  that would be nice!  and so i worked on it instead and with the help of macro recordings, spell checking seems to be a piece of cake.  but i decided to work on it another way than what is shown in the sample which is very good to say the least.  however, this is an rtf format and so we needed another approach.  

what i have decided to do, to preserve everything, is to save the contents of the rtf control (textrtf property) somewhere inside my harddisk, in the user's temp folder and open it via automation.  so here we go:

    lcfilertf = addbs(getenv("tmp"))+sys(3)+".rtf"
    loword = createobject("word.application")

so far so good.  to activate spell checking utilizing word inside vfp and per the sample i have read, it is as simple as this:  


but then why be satisfied with simple spell checking when we can also check the grammar?  by studying the recorded macros, we can achieve both in vfp by this single command instead:


and we are on the go!  my advice, forget about checkspelling() from this day onwards!  needles to say, use checkgrammar() instead.

to update the content of the rtf control, all we need to do now is:

a.  select the entire corrected document inside word:  


b.  copy into clipboard the selection:


c.  bring back the focus to the olertf:  


d.  select the entire original rtf via sendkeys():  


e.  finally paste the corrected ones:  


now what surprises me is it did not work! lol!  it worked with the image insertion (enhanced rtf tool revealed) but it does not in this case. i am not convinced though that the clipboard is empty so i changed tactic by replacing steps c to e with a simple:

    thisform.olertf.textrtf = _cliptext

and viola!  rtf contents is replaced with what is in the clipboard which is the spell and grammatically corrected texts.

gotcha!  but that's it!  only pure texts.  replacing contents of an editbox with corrected text is easy because editbox uses only pure text.  but the reason why we use an rtf control is so we can preserve the text formatting and the images. so above is totally unacceptable!

back to the planning board, an easy solution pops in my mind again and that is, forget also about the whole copy-pasting scenario.  make a complete turn around and do it again another way.  intrigued?  download sample to see how!

get the attachment here.  enjoy!

Leave a Reply

Your email address will not be published. Required fields are marked *