INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login




Remember Me
Forgot Password?
Join Us!

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.
Jobs from Indeed

Link To This Forum!

Partner Button
Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

StewartUK (Programmer) (OP)
28 Sep 04 4:58
This follows on from Thread1251-924215

I am using VFP8 but haven't really got to grips with TRY...CATCH...FINALLY (TCF).

Here is a snippet of code (there is more code before and after this bit):

CODE

IF NOT TextCopied
   oWord = CREATEOBJECT("Word.Application")
   WAIT WINDOW NOWAIT "Mailmerge - copying text"
   oDoc = oWord.Documents.Open(THIS.txtLetter.Value)
   oRange = oDoc.Range()
   oRange.Copy()
   CopiedText = _CLIPTEXT
   && ....assign the clipboard contents to a variable
   &&     to prevent problems should the user copy
   &&     some text to the clipboard in another application
   TextCopied = .T.
ENDIF

The line oDoc = oWord.Documents.Open(THIS.txtLetter.Value) sometimes causes an error.

To implement TCF, should I:

  1. put the whole IF...ENDIF inside the TRY and, if it caused an error, set a variable to FALSE and test that variable in the line beyond the TRY...ENDTRY to see if the rest of the code should execute
  2. put just the offending line inside the TCF structure
  3. put the preceding lines and all the lines that follow inside the TCF structure?
Thanks,

Stewart
wgcs (Programmer)
28 Sep 04 10:15
Everyone has their own style, but here's how I'd handle this situation:

CODE

IF NOT TextCopied
   TRY
     WAIT WINDOW NOWAIT "Mailmerge - copying text"

     oWord = CREATEOBJECT("Word.Application")
     oDoc = oWord.Documents.Open(THIS.txtLetter.Value)
     oRange = oDoc.Range()
     oRange.Copy()
     CopiedText = _CLIPTEXT
     && ....assign the clipboard contents to a variable
     &&     to prevent problems should the user copy
     &&     some text to the clipboard in another application
     TextCopied = .T.
  CATCH TO oExc
    messagebox('There was a problem: '+oExc.Message,0,'Error')
  FINALLY
    RELEASE oRange
    RELEASE oDoc
    RELEASE oWord
  ENDTRY
  * if it wasn't successful, TextCopied never was set .T.
ENDIF

It really all depends on where you want user interface.

- Bill

Get the best answers to your questions -- See FAQ481-4875.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close