用VB编写一个计时器,怎么编

用VB编写一个计时器,怎么编,第1张

private sub cmd1_click()

if cmd1caption="开始" then

text1=format(now-now,"hh:mm:ss")

timer1enabled=ture

cmd1caption="暂停"

else

timer1enabled=false

cmd1caption="继续"

end sub

private cmd2_click()

text1=format(now-now,"hh:mm:ss")

timer1enabled=ture

end sub

private timer1_timer()

text1=Format(DateAdd("s", 1, cdate(text1)), "hh:mm:ss")

end sub

执行完语句e之后才开始计时,给你下面代码试试,在d出HELLo对话框之后,你等5秒钟在关闭对话框,你会发现timer在5秒后才开始计时,而不是在执行完timer1enabled=true之后立马开始计时

Private Sub Command1_Click()

Timer1Enabled = True

MsgBox "HELLO!"

End Sub

Private Sub Timer1_Timer()

Static N As Integer

N = N + 1

Label1Caption = N

End Sub

放一个timer控件,一个text控件,都用默认的名字,调整好text控件的位置和大小,把代码放到代码窗口中即可。

Dim T1 As Date

Private Sub Form_Load()

Form1AutoRedraw = True

T1 = Time + CDate("0:03:00")

Text1Text = Format(CDate(T1 - Time))

Timer1Interval = 200

End Sub

Private Sub Timer1_Timer()

If Text1Text = "0:00:00" Then

Timer1Enabled = False

MsgBox "时间到"

Else

Text1Text = Format(CDate(T1 - Time))

End If

End Sub

注:改变程序中“0:03:00”数值的大小,就可以改变倒计时的时间长短。

已经运行过。

给你加多一个暂停的按钮,不喜欢可以不用。

窗体中一个TEXTBOX,三个COMMAND,一个TIMMER,看不到字就把TEXTBOX弄大点

Private Declare Function GetTickCount Lib "kernel32" () As Long

Public TStart, TNow, TLast, TMinute, TSecond, TTotal

Private Sub Command1_Click()

Command1Enabled = False: Command2Enabled = True: Command4Enabled = False

Text1Text = ""

End Sub

Private Sub Command2_Click()

Command3Enabled = True

Timer1Enabled = True

TTotal = TLast + TTotal

TStart = GetTickCount

Call Timer1_Timer

End Sub

Private Sub Command3_Click()

Command1Enabled = True: Command2Enabled = False

Command3Enabled = False: Command4Enabled = True

Timer1Enabled = False

TStart = 0: TEnd = 0: LTime = 0: TMinute = 0: TSecond = 0: TLast = 0

End Sub

Private Sub Command4_Click()

End

End Sub

Private Sub Form_Load()

Command1Caption = "开始": Command2Caption = "计时": Command3Caption = "停止": Command4Caption = "退出"

Command1Default = True: Command2Enabled = False: Command3Enabled = False

Timer1Interval = 1000: Timer1Enabled = False

TStart = 0: TEnd = 0: LTime = 0: TMinute = 0: TSecond = 0: TLast = 0

End Sub

Private Sub Timer1_Timer()

TNow = GetTickCount

TLast = Val(TNow - TStart) \ 1000

TMinute = TLast \ 60

TSecond = TLast Mod 60

Text1Text = "距你本次点击[计时]的时间为" & TMinute & ":" & TSecond & vbCrLf & "从第一次点击[计时]到本次点击经过了:" & TTotal & "秒"

End Sub

画一个command 一个timer

Private Sub Command1_Click()

Timer1Enabled = True

End Sub

Private Sub Form_Load()

Timer1Enabled = False

Timer1Interval = 1000

Command1Caption = "开始计时"

End Sub

Private Sub Timer1_Timer()

Command1Caption = Val(Command1Caption) + 1

End Sub

以上就是关于用VB编写一个计时器,怎么编全部的内容,包括:用VB编写一个计时器,怎么编、VB 计时器开始计时是在什么时候、VB计时器原代码等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

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

原文地址: http://outofmemory.cn/zz/10213440.html

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

发表评论

登录后才能评论

评论列表(0条)

保存