求用VB编一个秒表的程序谁能帮助解决一下啊

求用VB编一个秒表的程序谁能帮助解决一下啊,第1张

新建一个EXE标准工程,

在FORM1里添加控件

命令按钮Command1(Caption属性为"开始")

命令按钮Command2(Caption属性为"停止")

文本框Text1

计时器Timer1(Interval属性为100,Enabled属性为False)

打开代码窗口,输入代码

Private

SS

As

Long,

S

As

Long,

M

As

Long,

H

As

Long

'S=秒,M=分,H=时

Private

Sub

Command1_Click()

S

=

0

M

=

0

H

=

0

SS

=

0

Text1.Text

=

H

&

":"

&

M

&

":"

&

S

Timer1.Enabled

=

True

End

Sub

Private

Sub

Command2_Click()

S

=

0

M

=

0

H

=

0

SS

=

0

Timer1.Enabled

=

False

End

Sub

Private

Sub

Form_Load()

Timer1.Interval

=

100

Timer1.Enabled

=

False

End

Sub

Private

Sub

Timer1_Timer()

If

SS

<

9

Then

SS

=

SS

+

1

Else

SS

=

0

If

S

<

59

Then

S

=

S

+

1

Else

S

=

0

If

M

<

59

Then

M

=

M

+

1

Else

M

=

0

H

=

H

+

1

End

If

End

If

End

If

Text1.Text

=

H

&

":"

&

M

&

":"

&

S

&

"."

&

SS

End

Sub

简单的么,用timer控件做,精确些的么用,timer函数做.

时钟和倒计时很简单的了自己做一下

下面是 一个秒表程序,command 3个,label 1个.

Option Explicit

Dim PP As Boolean

Dim SS As Boolean

Dim TT As Single

Private Sub Command1_Click() '开始

TT = 0

PP = False

SS = False

Command1.Enabled = False

Command2.Enabled = True

Command3.Enabled = True

Command2.Caption = "暂停"

tmr

End Sub

Private Sub tmr() '秒表

Dim t As Single

t = Timer

Do

showTT Timer - t + TT

DoEvents

Loop Until SS Or PP

TT = Timer - t + TT

End Sub

Private Sub showTT(ByVal t As Single)

Dim h As Integer

Dim s As String

h = Int(t / 3600)

t = t - h * 3600

s = h &":"

h = Int(t / 60)

s = s &Format(h, "00") &":"

t = t - h * 60

h = Int(t)

s = s &Format(h, "00") &"."

t = Int((t - h) * 100)

s = s &t

Label1.Caption = s

End Sub

Private Sub Command2_Click() '暂停和继续

PP = Not PP

Command2.Caption = IIf(PP, "继续", "暂停")

If Not PP Then tmr

End Sub

Private Sub Command3_Click()

SS = True

Command1.Enabled = True

Command2.Enabled = False

Command3.Enabled = False

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


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

原文地址: http://outofmemory.cn/yw/8172443.html

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

发表评论

登录后才能评论

评论列表(0条)

保存