VB多功能计时器代码

VB多功能计时器代码
VB多功能计时器代码

VB多功能计时器代码

frmTimer窗体控件:

commandbutton * 2

picturebox * 1

pictureclip(注:图片剪切控件) * 1

timer * 3

(注:此处只给出了控件类型,控件名祥

见代码)

frmTimer 的代码

Option Explicit

Public t As Integer, str As String

Public h As Integer, m As Integer, s As Integer

Private Sub Show_LED(picTimer As PictureBox, str As String) '显示图片的通用过程

Dim s As String * 1

Dim pos As Integer

Dim n As Integer

Dim i As Integer

For i = 1 To Len(str)

s = Mid(str, i, 1)

n = -1

Select Case s

Case "0" To "9"

n = CInt(s)

Case ":"

n = 10

Case "-"

n = 11

Case "."

n = 12

Case "a", "A"

n = 13

Case "p", "P"

n = 14

Case " "

n = 15

End Select

If n <> -1 Then

picTimer.PaintPicture PCTimer.GraphicCell(n), pos, 0 pos = pos + 300

End If

Next

End Sub

Private Sub cmdRestart_Click() '秒表的回零

h = 0

m = 0

s = 0

str = ""

cmdStart.Caption = "开始"

Timer1.Enabled = False: str = "00:00:00"

Cls

Call Show_LED(picTimer, str) End Sub

Private Sub cmdStart_Click() '秒表的开始和暂停控制If cmdStart.Caption = "开始" Then

h = 0

m = 0

s = 0

cmdStart.Caption = "暂停"

Timer1.Enabled = True

cmdRestart.Enabled = False

Exit Sub

ElseIf cmdStart.Caption = "暂停" Then cmdStart.Caption = "继续"

Timer1.Enabled = False

cmdRestart.Enabled = True

Exit Sub

Else

cmdStart.Caption = "暂停"

Timer1.Enabled = True

cmdRestart.Enabled = False

Exit Sub

End If

End Sub

Private Sub Form_Load() '窗体加载

Call mnuClock_Click End Sub

Private Sub mnuClock_Click() '时钟picTimer.Cls

Me.Cls

Timer1.Enabled = False

Timer2.Enabled = False

cmdStart.Visible = False

cmdRestart.Visible = False

frmTimer.Caption = "时钟"

Timer3.Enabled = True

picTimer.Visible = True

Cls

End Sub

Private Sub mnuCuntDwnClock_Click() '倒计时picTimer.Cls

Me.Cls

Timer1.Enabled = False

Timer3.Enabled = False

cmdStart.Visible = False

cmdRestart.Visible = False

frmSet.Visible = True

frmTimer.Caption = "倒计时钟" picTimer.Visible = True End Sub Private Sub mnuExit_Click() '退出选项Unload frmTimer: Unload frmSet

End Sub

Private Sub mnuStopwatch_Click() '秒表picTimer.Cls

Me.Cls

Timer1.Enabled = False

Timer2.Enabled = False

Timer3.Enabled = False

cmdStart.Visible = True

cmdRestart.Visible = True

frmTimer.Caption = "秒表"

picTimer.Visible = True End Sub Private Sub Timer1_Timer() '秒表计时过程str = ""

s = s + 1

If s = 100 Then '秒表数字显示的处理

s = 0

m = m + 1

If m = 60 Then

m = 0

h = h + 1

If h = 24 Then

h = 0

End If

End If

End If

If h < 10 Then '数字显示格式的处理

str = str & 0 & h

Else: str = str & h

End If

If m < 10 Then

str = str & ":" & 0 & m

Else: str = str & ":" & m

End If

If s < 10 Then

str = str & ":" & 0 & s

Else: str = str & ":" & s

End If

Cls

Call Show_LED(picTimer, str) End Sub Private Sub Timer2_Timer() '倒计时计时过程picTimer.Cls

str = ""

t = h * 3600 + m * 60 + s

If t >= 1 Then

s = s - 1

If s = -1 Then

s = 59

m = m - 1

End If

If m = -1 Then

m = 59

h = h - 1

End If

If h < 10 Then

str = str & "0" & h

Else

str = str & ":" & h

End If

If m < 10 Then

str = str & ":" & "0" & m Else

str = str & ":" & m

End If

If s < 10 Then

str = str & ":" & "0" & s Else

str = str & ":" & s

End If

Cls

Call Show_LED(picTimer, str)

Else

picTimer.Visible = False

Cls

frmTimer.Print "时间到"

Timer2.Enabled = False

End If

End Sub

Private Sub Timer3_Timer() '时钟显示过程str = CStr(Now)

Call Show_LED(picTimer, str)

Cls

End Sub

frmTimer窗体控件:

text * 3

commandbuton * 1

label * 3 (注:控件名称参照代码)

frmSet 的代码

Option Explicit

Private Sub cmdCuntStart_Click() frmTimer.h = Val(txtInput(0)) frmTimer.m = Val(txtInput(1)) frmTimer.s = Val(txtInput(2))

If frmTimer.h + frmTimer.m + frmTimer.s = 0 Then

Call MsgBox("输入错误,请重新输入", 48, "多功能计时器") Else

frmTimer.Timer2.Enabled = True

Unload frmSet

End If

End Sub

相关主题
相关文档
最新文档