惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

V
Visual Studio Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
博客园 - 聂微东
博客园 - 【当耐特】
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
C
Check Point Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
美团技术团队
WordPress大学
WordPress大学
Last Week in AI
Last Week in AI
Y
Y Combinator Blog
IT之家
IT之家
T
Tailwind CSS Blog
月光博客
月光博客
Vercel News
Vercel News
V
V2EX
Engineering at Meta
Engineering at Meta
B
Blog
Stack Overflow Blog
Stack Overflow Blog
A
About on SuperTechFans
Hugging Face - Blog
Hugging Face - Blog
人人都是产品经理
人人都是产品经理
腾讯CDC
I
InfoQ

博客园 - MyFavorite

成长、改变、突破 软件工程相关整理 INCLUDE COMMON FILES IN HTML USING JQUERY Oracle取TOP N条记录 Oracle:分割字符串 use CheckBoxMultipleChoice in wicket 5个必须掌握的maven命令 根据对象名获取对象 外网SQL服务器设置 cmd命令控制台窗口一闪就消失解决办法 jdbc访问数据库 - MyFavorite - 博客园 java与MSSQL2000连接 - MyFavorite - 博客园 关于java CountDownLatch java InputStream读取数据问题 MyEclipse中防止代码格式化时出现换行的情况的设置 java监控多个线程的实现 TCP连接状态 Java定时器代码 java下的日期函数实现
VB6.0调用SetTimer实现定时器
MyFavorite · 2011-05-27 · via 博客园 - MyFavorite

Timer.bas:

Option ExplicitDeclare Function SetTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
Declare Function KillTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long) As LongPublic Sub TimerProc(ByVal hwnd As Long, ByVal uMsg As Long, ByVal idEvent As Long, ByVal dwTime As Long)
MsgBox Now()
End Sub

窗体代码:

Option ExplicitDim lngTimerID As Long
Dim BlnTimer As BooleanPrivate Sub Form_Load()
BlnTimer
= False
Command1.Caption
= "定时开始"
End SubPrivate Sub Form_Unload(Cancel As Integer)
KillTimer
0, lngTimerID
End SubPrivate Sub Command1_Click()
If BlnTimer = False Then
'每5秒钟调用一次函数
lngTimerID = SetTimer(0, 0, 5000, AddressOf TimerProc)
BlnTimer
= True
Command1.Caption
= "定时结束"
Else
KillTimer
0, lngTimerID
BlnTimer
= False
Command1.Caption
= "定时开始"
End If
End Sub

说明:
TimerProc函数定义一定要放在bas模块文件中,否则运行代码"lngTimerID = SetTimer(0, 0, 5000, AddressOf TimerProc)"会报错,

提示:操作符 AddressOf 使用无效。