如何用VB程序做计时器

如何用VB程序做计时器,第1张

3个标签,2个按钮,1个计时器控件

Private Sub Command1_Click() '开始/暂停

If Timer1Enabled = True Then

Timer1Enabled = False

Else

Timer1Enabled = True

End If

End Sub

Private Sub Command2_Click() '停止清0

Label1 = "0"

Label2 = "0"

Label3 = "0"

Timer1Enabled = False

End Sub

Private Sub Form_Load() '初始设置

Label3 = "0"

Label2 = "0"

Label1 = "0"

Timer1Interval = 1000

Timer1Enabled = False

End Sub

Private Sub Timer1_Timer()

Label3 = Label3 + 1

If Label3 = 60 Then

Label3 = "0"

Label2 = Label2 + 1

If Label2 = 60 Then

Label2 = "0"

Label1 = Label1 + 1

End If

End If

End Sub

这个好理解一些:

Randomize

a = TimeSerial(Int(Rnd 24), Int(Rnd 60), Int(Rnd 60))

Print a

Private Sub Form_Load()

Timer1Interval = 60000

Timer1Enabled = True

End Sub

Private Sub Timer1_Timer()

If Hour(Now) = 18 And Minute(Now) = 30 Then

Shell "notepadexe", vbNormalFocus

End If

End Sub

以上代码是在每天的18:30运行“记事本”

两个command,(分别是显示和清除)一个text来显示时间,一个timer

属性设置:

text1清除内容,钟表的interva设为1000,表示1秒,enadled设为false表示为不可用。

显示命令:

Timer1Enabled = True

Text1Text = Date + Time

清除的命令

Timer1Enabled = False

Text1Text = ""

钟表的命令

Text1Text = Date + Time

按我说的做吧,保证不会错,我先在电脑上运行了的。

详细代码如下:Private Sub Command1_Click()Dim Date1 As Date, Date2 As Date, Days As IntegerDate1 = DateMsgBox "还剩" & Days & "天"ElseMsgBox "倒计时日期输入错误,请重新检查"End IfElseMsgBox "时间格式输入错误!

以上就是关于如何用VB程序做计时器全部的内容,包括:如何用VB程序做计时器、VB中随机产生一个今天的时间怎么写程序、VB中怎样实现在指定时间运行指定程序等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zz/10121220.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-05
下一篇2023-05-05

发表评论

登录后才能评论

评论列表(0条)

    保存