VB多功能计时器代码

合集下载
相关主题
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

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

相关文档
最新文档