用VB编写一个秒表

用VB编写一个秒表,第1张

'一个标签,两个按钮山谈,一个计时器

'标签显示时间野唯局,按钮一控制秒表,按钮二清零。

Dim m As Integer, s As Integer, ms As Integer, flag As Boolean

Private Sub Command1_Click()

If flag = False Then

Timer1.Interval = 10

flag = True

Else

Timer1.Interval = 0

flag = False

End If

End Sub

Private Sub Command2_Click()

flag = False

Timer1.Interval = 0

m = 0

s = 0

ms = 0

Label1.Caption = "00:00:00"

End Sub

Private Sub Timer1_Timer()

ms = ms + 1

If ms = 100 Then

s = s + 1

ms = 0

End If

If s = 60 Then

m = m + 1

s = 0

End If

Label1.Caption = Format(m, "00:") &Format(s, "00:") &Format(ms, "00"颂让)

End Sub

Option Explicit

Dim MinSec As Integer

Dim Sec As Integer

Dim Minute As Integer

Dim Hour As Integer

Private Sub Command1_Click() '开始按钮

Timer1.Enabled = True

End SubPrivate Sub Command2_Click() '停止

Timer1.Enabled = False

End SubPrivate Sub Command3_Click() '清除

Timer1.Enabled = False

Hour = 0

Minute = 0

MinSec = 0

Sec = 0

Label1.Caption = Format(Hour, "00") &"时" &Format(Minute, "00") &"分" &Format(Sec, "00") &"秒" &Format(MinSec, "00")

End SubPrivate Sub Form_Load()

Timer1.Enabled = False

Timer1.Interval = 10

Form1.Caption = "秒表"

Command1.Caption = "模颤开始"

Command2.Caption = "停止"

Command3.Caption = "清除"

End SubPrivate Sub Timer1_Timer()

MinSec = MinSec + 1

If MinSec = 100 Then

MinSec = 0

Sec = Sec + 1

If Sec = 60 Then

Sec = 0

Minute = Minute + 1

If Minute = 60 Then

Minute = 0

Hour = Hour + 1

Else

End If

Else

End If

Else

End If

Label1.Caption = Format(Hour, "缓搭00") &"时" &Format(Minute, "00") &"分"旦哪败 &Format(Sec, "00") &"秒" &Format(MinSec, "00")

End Sub

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

Private Sub Command1_Click() '开始/暂停

If Timer1.Enabled = True Then

Timer1.Enabled = False

Else

Timer1.Enabled = True

End If

End Sub

Private Sub Command2_Click() '停止清0

Label1 = "0"

Label2 = "漏纤0"

Label3 = "0"

Timer1.Enabled = False

End Sub

Private Sub Form_Load() '初始设置

Label3 = "0"

Label2 = "0"

Label1 = "0"

Timer1.Interval = 1000

Timer1.Enabled = 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


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

原文地址:https://54852.com/yw/8222392.html

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

发表评论

登录后才能评论

评论列表(0条)

    保存