tags:

views:

457

answers:

3

Firstly, I am not a VFP programmer, so what I'm doing wrong is probably something simple.

I'm trying to extract some documents out of general fields in a VFP 9 database. I have a way of doing this by effectively copying and pasting the field into Word and then saving the Word document off to disk.

I have this all working inside the foxpro development environment in a .prg file.

Here's the guts of my code (most of which was copied from a Microsoft Support question):

DO WHILE NOT EOF()
    IF EMPTY(tnoteole) then
        SKIP
        LOOP
    ENDIF

    KEYBOARD "{ctrl+c} {ctrl+w}" 
    MODIFY GENERAL tnoteole 

    TRY
     .EditPaste
    CATCH
    ENDTRY

    .InsertPara

    filename = Path + ALLTRIM(STR(recnum)) + ".doc"
    .FileSaveAs(filename)
    .EditSelectAll
    .EditClear
    SKIP                     

    recnum = recnum + 1
ENDDO

My problem is that when I run this from inside the development environment it works fine, and the general field window flashes up on the screen and it gets pasted into Word, etc. But when I try running this from a complied exe (the process is triggered by the user clicking a button on a form - I have that much working - though I'd actually like it to be a batch job, with no user interaction required) Word opens, but that's as far as it gets. The general field doesn't flash up on the screen, and basically it just waits for ever.

(Oh and in case you're wondering about the nasty try/catch thing, I found some exception with Word when pasting some fields, but the try/catch works fine in the dev. environment, so I don't think that's the cause of my problems.)

So, how can I make this work? I'm kinda feeling my way around in the darkness of foxpro.

Please help! :)

Thanks,

Craig

+2  A: 

A few things:

  • Is this a VFP compiled EXE? Do you have a 'READ EVENTS' command in it? Otherwise the exe code will run and then exit immediately, which sounds a bit like your problem.

  • Where are you getting the Path variable from? Could that vary between development and runtime?

  • Any settings which need to be set must be explicitly in the runtime environment - SET EXCLUSIVE and SET SAFE spring to mind.

Otherwise, a bit of MessageBox debugging or logging should tell you how far you're getting through the program and what your variables are set as, which should be enough to get it working.

Updated: I was just looking at the Modify General documentation and you might need to use the NOWAIT clause with your Modify General command: NOMODIFY wouldn't hurt, either, and you might have to provide a DEFINEd window for the editing window to open in and include an IN WINDOW clause.

NOWAIT Continues program execution after the general field editing window is opened. The program doesn't wait for the editing window to be closed, but continues execution on the program line immediately following the line that contains MODIFY GENERAL NOWAIT. If you omit NOWAIT when MODIFY GENERAL is issued in a program, an editing window is opened and program execution pauses until the editing window is closed.

Stuart Dunkeld
Thanks for the response. I do have a READ EVENTS - and it's popping up a form. I've scattered some message boxes through the code, but not much help - basically it's getting stuck at the MODIFY GENERAL command, I think. The patch variable is coming from a command-line argument that I get from a parameter to the PRG. I can post come more code if it will help.
Craig Shearer
+1  A: 

Hi Craig,

I've been a foxpro developer since 1987, and VFP since 1993. If the data you have is not anything confidential, and you can get me a copy of say 20 records or so... I'll see if I can throw something together for you that would run unattended as an EXE outside development mode. Even if you give me a bogus non-General column AND the General column of data.

DRapp
That would be absolutely fantastic. How do I contact you? The data is confidential medical stuff, but I'm sure I can give you some bogus stuff. Actually, you can email me at craig (at) supacrash (dot) com. Look forward to hearing from you.
Craig Shearer
A: 

A General field is highly dependent on the automation information stored in the General field and in your case the Word doc. So if the machine you are running it on does not have Microsoft Word on it you will run into a problem. As you probably know, General fields are finicky.

My suggestion is to include the MODIFY GENERAL code inside of the TRY...CATCH and add some exception code to the CATCH so you can see what is going on here.

LOCAL loException AS Exception

TRY
    KEYBOARD "{ctrl+c} {ctrl+w}" 
    MODIFY GENERAL tnoteole 

    .EditPaste

    .InsertPara

    filename = Path + ALLTRIM(STR(recnum)) + ".doc"
    .FileSaveAs(filename)
    .EditSelectAll
    .EditClear
    SKIP                     

CATCH TO loException
    * Output problem to a text file for review after the process
    STRTOFILE(loException.Message + CHR(13) + CHR(10) ;
              " on " + TRANSFORM(loException.LineNo), ;
              "ExceptionLog.txt", 1)

ENDTRY

I also agree with the NOWAIT. Without some sample code I would only be guessing that the window opened also needs to be closed, or might eat up some resources you need on the machine.

Rick Schummer