一秒的速度太慢,我给你设置了001秒
Option Explicit
Dim MinSec As Integer
Dim Sec As Integer
Dim Minute As Integer
Dim Hour As Integer
Private Sub Command1_Click() '开始
Timer1Enabled = True
End Sub
Private Sub Command2_Click() '停止
Timer1Enabled = False
MsgBox "现在是" & Label2Caption
End Sub
Private Sub Command3_Click() '取消
Timer1Enabled = False
Hour = 0
Minute = 0
MinSec = 0
Sec = 0
Label2Caption = Format(Hour, "00") & "时" & Format(Minute, "00") & "分" & Format(Sec, "00") & "秒" & Format(MinSec, "00")
End Sub
Private Sub Form_Load()
Timer1Enabled = False
Timer1Interval = 10
End Sub
Private 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
Label2Caption = Format(Hour, "00") & "时" & Format(Minute, "00") & "分" & Format(Sec, "00") & "秒" & Format(MinSec, "00")
End Sub
代码如下:
Private x As DoublePrivate Sub Form_Load()
Timer1Interval = 100
Timer1Enabled = False
End Sub
Private Sub Command1_Click()
Timer1Enabled = True
End Sub
Private Sub Command2_Click()
Timer1Enabled = False
End Sub
Private Sub Command3_Click()
Timer1Enabled = False
x = 0
End Sub
Private Sub Timer1_Timer()
x = Round((x + 01), 1)
If x < 1 Then Text1 = "0" & x Else Text1 = x
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
Command1Enabled = False
Command2Enabled = True
Command3Enabled = True
Command2Caption = "暂停"
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
Label1Caption = s
End Sub
Private Sub Command2_Click() '暂停和继续
PP = Not PP
Command2Caption = IIf(PP, "继续", "暂停")
If Not PP Then tmr
End Sub
Private Sub Command3_Click()
SS = True
Command1Enabled = True
Command2Enabled = False
Command3Enabled = False
End Sub
Option Explicit
Dim Times As String, T As Long
Dim D As Integer, H As Integer, M As Integer, S As Integer
Private Sub Form_Load()
Form1AutoRedraw = True
Times = InputBox("输入时间(单位:秒)", "输入", 123456)
T = Val(Times)
S = T Mod 60
T = T \ 60
M = T Mod 60
T = T \ 60
H = T Mod 24
D = T \ 24
Print Val(Times); "秒="; D; "日"; H; "时"; M; "分"; S; "秒"
End Sub
下面是一个时钟的代码,
在对象窗口需要画一个圆shape1,随便画三条线
接着运行就ok了我试了就用一个timer和 line就行,只是要把line 在属性里改 index=0
Option Explicit
Private Sub Form_Load()
Timer1Interval = 1000
Form1Width = 4000
Form1Height = 4000
Form1Left = ScreenWidth \ 2 - 2000
Form1Top = (ScreenHeight - Height) \ 2
End Sub
Private Sub Form_Resize()
Dim i, Angle
Static flag As Boolean
If flag = False Then
flag = True
'画出表盘12个点和时、分、秒共15个Line
For i = 0 To 14
If i > 0 Then Load Line1(i)'这里容易出错,要在line属性里设置index=0
Line1(i)Visible = True
Line1(i)BorderWidth = 5
Line1(i)BorderColor = RGB(0, 128, 0) '设置Line的粗细和颜色
Next i
End If
Scale (-1, 2)-(1, -2)
For i = 0 To 14
Angle = i 2 Atn(1) / 3
Line1(i)X1 = 09 Cos(Angle)
Line1(i)Y1 = 09 Sin(Angle)
Line1(i)X2 = Cos(Angle)
Line1(i)Y2 = Sin(Angle)
Next i
End Sub
Private Sub timer1_Timer()
Const HH = 0
Const MH = 13
Const SH = 14
Dim Angle
Angle = 05236 (15 - (Hour(Now) + Minute(Now) / 60)) '设置时针
Line1(HH)X1 = 0
Line1(HH)Y1 = 0
Line1(HH)X2 = 03 Cos(Angle)
Line1(HH)Y2 = 03 Sin(Angle)
Angle = 01047 (75 - (Minute(Now) + Second(Now) / 60)) '设置分针
Line1(MH)BorderWidth = 3
Line1(MH)X1 = 0
Line1(MH)Y1 = 0
Line1(MH)X2 = 07 Cos(Angle)
Line1(MH)Y2 = 07 Sin(Angle)
Angle = 01047 (75 - Second(Now)) '设置秒针
Line1(SH)BorderWidth = 1
Line1(SH)X1 = 0
Line1(SH)Y1 = 0
Line1(SH)X2 = 08 Cos(Angle)
Line1(SH)Y2 = 08 Sin(Angle)
Form1Caption = Str(Now()) '窗口显示精确的日期和数字化的时间now=date+time怎样显示星期几weekday?
End Sub
以上就是关于vb 设计新建一个工程,完成“秒表计时”程序的设计,如图13-11所示。具体要求如下:全部的内容,包括:vb 设计新建一个工程,完成“秒表计时”程序的设计,如图13-11所示。具体要求如下:、怎样用VB做一个秒表计时器、跪求 vb多功能计时器代码 要有时钟 秒表 和倒计时的功能,秒表有暂停,开始功能的等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)