excel vba Application.OnTime [英] excel vba Application.OnTime

查看:42
本文介绍了excel vba Application.OnTime的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我上周问了一个关于这个的问题这里我发布了我的代码按要求但没有答复.不管怎样,我还有一些更具体的问题.

I asked a question about this last week here I posted my code as requested but no answer. Anyway, I have some more specific questions.

重置计时器时,Procedure参数的目的是什么?使用 Schedule:=False 进行回调是没有意义的.例如,如果回调函数不再在范围内,会发生什么?定时器是否仍然正常复位?这就是为什么我看到的大多数示例(包括 Chip Pearson - 不幸的是,由于某种原因我不允许包含链接)使用 On Error Resume Next 进行 OnTime 调用而且,很抱歉再次提问,但为什么要这样做?

When resetting the timer, what is the purpose of the Procedure argument? It doesn't make sense to have a call-back with Schedule:=False. What happens if the call-back function is no longer in scope for example? Is the timer still reset properly? Is this why most of the examples I've seen (including Chip Pearson - unfortunately, for some reason I'm not allowed to include the link) proceed the OnTime call with On Error Resume Next And, sorry to ask again, but why is this done?

我的理解是计时器由 EarliestTime 参数注册,这是唯一标识它的计时器的序列号".
Procedure 参数是否也包含在注册和后续识别过程中?

My understanding is that the the timer is registered by the EarliestTime argument and that this is the "serial number" for the timer that uniquely identifies it.
Is the Procedure argument also included in the registration and subsequent identification process as well?

如果回调过程包含在计时器触发时不再存在的对象中,会发生什么情况?或者更一般地说,如果在计时器触发并尝试执行回调过程时出现错误,会发生什么情况?

What happens if the call-back procedure is contained in an object that no longer exists when the timer fires? Or more generally, what happens if there is some error when the timer fires and tries to execute the call-back procedure?

如果包含 LatestTime 参数,如果计时器无法触发,那么在该时间之后会发生什么?Windows 会完全清除计时器吗?

If the LatestTime argument is included, what happens after that time if the timer has not been able to fire? Does Windows erase the timer completely?

推荐答案

我的理解是计时器由 EarliestTime 参数注册,这是唯一标识它的计时器的序列号".

不知道你在哪里读到的?并不是说这是一个聪明的做法,但原则上您可以使用相同的 EarliestTime 安排两个或多个 OnTime 运行.所以这并不使它独一无二.EarliestTimeProcedure 的组合使其独一无二.

Not sure where you read this? Not that it's a smart thing to do, but you could in principle schedule two or more OnTime runs with the same EarliestTime. So that doesn't make it unique. The combination of EarliestTime and Procedure makes it unique.

在重置定时器时,Procedure 参数的目的是什么?

不确定重置"计时器是什么意思;你的意思是用 Schedule := True 还是 Schedule := False 调用 OnTime ?

Not sure what you mean by "resetting" the timer; do you mean calling OnTime with Schedule := True or Schedule := False?

无论哪种方式,如果您不指定 Procedure 参数,它怎么知道要运行哪个过程(或运行哪个过程要取消)?这就是它的用途.

Either way, how else is it supposed to know which procedure to run (or which procedure run to cancel) if you don't specify the Procedure argument? That's what it's for.

我建议您尝试一下并说服自己.

I suggest you try it out and convince yourself.

如果回调过程包含在计时器触发时不再存在的对象中,会发生什么情况?或者更一般地说,如果在计时器触发并尝试执行回调过程时出现错误,会发生什么情况?

好吧,你有没有尝试过自己找出答案?没有什么神秘的事情发生.您会像往常一样收到错误消息.

Well, have you tried it to find out for yourself? Nothing mysterious happens. You get an error message as usual.

如果包含 LatexTime 参数,那么如果计时器无法触发,那么在该时间之后会发生什么?Windows 会完全清除计时器吗?

我想你可以这样说.程序不会运行.请参阅 VBA 帮助:

I guess you could put it that way. The procedure won't be run. See VBA help:

例如,如果将最新时间设置为EarliestTime + 30 并且Microsoft Excel 在EarliestTime 未处于准备、复制、剪切或查找模式,因为另一个过程正在运行,Microsoft Excel 将等待30 秒以完成第一个过程.如果 Microsoft Excel 在 30 秒内未处于就绪模式,则不会运行该过程.

For example, if LatestTime is set to EarliestTime + 30 and Microsoft Excel is not in Ready, Copy, Cut, or Find mode at EarliestTime because another procedure is running, Microsoft Excel will wait 30 seconds for the first procedure to complete. If Microsoft Excel is not in Ready mode within 30 seconds, the procedure won’t be run.

这篇关于excel vba Application.OnTime的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆