如何运行code(不查询)时,显示在状态栏进度进度、状态栏、code

由网友(是否习惯这样)分享简介:我已经发布了有关问题,同时运行的查询在MS Access更新状态栏2010。请参阅How正在运行的查询序列时,在MS Access 的,如果你有兴趣来显示在状态栏上的进步。I have already posted a question about updating the status bar while runn...

我已经发布了有关问题,同时运行的查询在MS Access更新状态栏2010。请参阅How正在运行的查询序列时,在MS Access 的,如果你有兴趣来显示在状态栏上的进步。

I have already posted a question about updating the status bar while running queries in MS Access 2010. Please see How to show progress on status bar when running a sequence of queries in MS Access if you are interested.

这是一些code不工作很简单的问题。我希望,如果有人能回答这个问题,它可以帮助我的,为什么code对于更复杂的问题不工作的认识。

This is a very simple question about some code that doesn't work. I hope that if someone can answer it, it may help my understanding of why the code for the more complicated question doesn't work.

Function PutMessageInStatusBar1()

Dim RetVal As Variant
Dim i As Long

RetVal = SysCmd(4, "Before loop 1")
For i = 1 To 500000000
Next

RetVal = SysCmd(4, "Before loop 2")
For i = 1 To 500000000
Next

RetVal = SysCmd(4, "Before loop 3")
For i = 1 To 500000000
Next
RetVal = SysCmd(5)

End Function

我写了一个宏运行的code。它开始转动警告关闭,然后调用上面的函数,显示一个消息框说完了,然后打开警告的。

I wrote a macro to run the code. It starts by turning warnings off, then calls the above function, displays a message box to say "Finished" and then turns warnings on.

当我运行它时,状态栏上首先显示准备就绪。有一个停顿,presumably而code上环1,然后显示回路2前,最后循环3之前。

When I run it, the status bar first shows "Ready". There is a pause, presumably while the code is running Loop 1. Then it shows "Before loop 2" and finally "Before loop 3".

为什么它不显示循环之前1?

Why doesn't it display "Before loop 1"?

我试图把将RetVal = syscmd(5)就在函数的开始,看它是否取得了任何区别。事实并非如此。

I tried putting RetVal = syscmd(5) right at the beginning of the function to see if it made any difference. It didn't.

推荐答案

呼叫的DoEvents 之后的每个 SysCmd 通话。这将标志着Windows之前的code的进步来更新显示。

Call DoEvents after each SysCmd call. That will signal Windows to update the display before your code advances.

在此功能,每一个状态栏消息是可见的下一个显示之前。

In this function, each status bar message is visible before the next is displayed.

Function PutMessageInStatusBar2()
    Const lngMilliseconds As Long = 1000

    SysCmd acSysCmdSetStatus, "Before loop 1"
    DoEvents
    Sleep lngMilliseconds
    SysCmd acSysCmdSetStatus, "Before loop 2"
    DoEvents
    Sleep lngMilliseconds
    SysCmd acSysCmdSetStatus, "Before loop 3"
    DoEvents
    Sleep lngMilliseconds
    SysCmd acSysCmdSetStatus, "Done."
    DoEvents
    Sleep lngMilliseconds

    SysCmd acSysCmdClearStatus

End Function

睡眠是基于Windows API的方法和标准模块的声明部分声明:

Sleep is based on a Windows API method and is declared in the Declarations section of a standard module:

Option Compare Database
Option Explicit
Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
阅读全文

相关推荐

最新文章