excel - 以毫秒为单位的 Excel VBA Ontime 函数
问题描述
我编写了这段代码,使用 ontime 函数每秒运行一个过程:
Sub startTimer()
Application.OnTime (Now + TimeValue("00:00:01")), "increment"
End Sub
Sub increment()
'some code here
startTimer
End Sub
代码工作正常,但是有没有办法增加几分之一秒(例如:10 ms)?
解决方案
尝试这个:
Sub startTimer()
Const MILLISECOND_MULTIPLIER As Double = 0.000000011574;
' bracket is optional, but kept for clarity
Application.OnTime (Now + (MILLISECOND_MULTIPLIER * 10)), "increment")
End Sub
这受到来自现有答案的评论的启发。
推荐阅读
- amazon-dynamodb - 我应该在这个 dynamodb 表中选择哪一列作为二级索引?
- javascript - 为什么我不能对这个元素应用任何东西?
- asp.net - ASP.NET - 实体框架下拉列表
- jquery - jQuery动画队列:true同时发生
- arrays - 将数组分成两部分,使它们的总和之差最小
- javascript - VueJS 和“vue-markdown”,当触发 `rendered` 事件时 DOM 仍未准备好
- javascript - Safari 跳过 XMLHttpRequests?
- python - 如何将带有字符串的列表转换为二维列表
- javascript - 同时使用 Webrtc 和 Webspeech API
- keras - 从具有多个列名的数据帧流入 y_col 生成类型错误