Visual Foxpro 修改通用字段

发布于 2024-07-25 22:51:21 字数 1003 浏览 2 评论 0原文

首先,我不是VFP程序员,所以我做错的事情可能很简单。

我正在尝试从 VFP 9 数据库的常规字段中提取一些文档。 我有一种方法可以做到这一点,即有效地将字段复制并粘贴到 Word 中,然后将 Word 文档保存到磁盘上。

我将所有这些都在 FoxPro 开发环境中的 .prg 文件中进行。

这是我的代码的核心内容(其中大部分是从 Microsoft 支持问题复制的):

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

我的问题是,当我从开发环境内部运行它时,它工作正常,并且常规字段窗口在屏幕上闪烁并被粘贴但是当我尝试从编译的 exe 运行它时(该过程是由用户单击表单上的按钮触发的 - 我有很多工作 - 尽管我实际上希望它是一个批处理作业,无需用户交互)Word 将打开,但也仅此而已。 一般字段不会在屏幕上闪烁,基本上它只是永远等待。

(哦,如果你想知道令人讨厌的 try/catch 的事情,我在粘贴某些字段时发现了 Word 的一些异常,但是 try/catch 在开发环境中工作正常,所以我不认为这是原因我的问题。)

那么,我怎样才能做到这一点呢? 我有点在 FoxPro 的黑暗中摸索。

请帮忙! :)

谢谢,

克雷格

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

一抹微笑 2024-08-01 22:51:21

一些事情:

  • 这是一个 VFP 编译的 EXE 吗? 您是否有“读取事件”命令在里面? 否则exe代码将运行然后立即退出,这听起来有点像你的问题。

  • 你从哪里获取 Path 变量? 开发和运行时之间会有所不同吗?

  • 任何需要设置的设置都必须在运行时环境中显式设置 - SET EXCLUSIVE 和 SET SAFE 浮现在脑海中。

    任何需要设置的设置

否则,一些 MessageBox 调试或日志记录应该会告诉您程序的运行情况以及变量的设置,这应该足以使其正常工作。

更新:我只是在查看修改常规 文档,您可能需要将 NOWAIT 子句与“修改常规”命令一起使用:NOMODIFY 也不会造成损害,并且您可能必须提供一个 DEFINEd 窗口以供编辑窗口打开并包含 IN WINDOW 子句。

现在等待
后继续执行程序
一般字段编辑窗口是
打开。 该程序不等待
编辑窗口要关闭,但是
继续执行程序
紧接着该行的行
其中包含“立即修改常规”。
如果 MODIFY GENERAL 时省略 NOWAIT
在节目中发布,编辑
窗口打开并执行程序
暂停,直到编辑窗口出现
已关闭。

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.

你如我软肋 2024-08-01 22:51:21

我自 1987 年以来一直是 Foxpro 开发人员,自 1993 年以来一直是 VFP。如果您拥有的数据不是什么机密,您可以给我一份大约 20 条记录的副本...我看看是否可以抛出一些东西一起为您提供无人值守的 EXE 外部开发模式。 即使您给我一个虚假的非常规列和数据的常规列。

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.

莫相离 2024-08-01 22:51:21

常规字段高度依赖于存储在常规字段中的自动化信息,在您的情况下是 Word 文档。 因此,如果您运行它的计算机上没有 Microsoft Word,您将会遇到问题。 您可能知道,通用字段非常挑剔。

我的建议是在 TRY...CATCH 中包含 MODIFY GENERAL 代码,并向 CATCH 添加一些异常代码,以便您可以看到这里发生了什么。

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

我也同意NOWAIT。 如果没有一些示例代码,我只能猜测打开的窗口也需要关闭,或者可能会消耗机器上所需的一些资源。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文