怎样用VB编写电子时钟?还要带上秒表计时器!
2011-08-04
展开全部
第一步,打开vb
第二部,添加一个计时器timer,一个文字标签label
第三部,输入代码,代码如下
Private Sub Form_Load()
picClock.Move (Me.ScaleWidth - 8 * 210) / 2, (Me.ScaleHeight - 315) / 2, 8 * 210, 315
Dim i&
For i = 0 To 7
picClock.PaintPicture picNumber.Picture, i * 210, 0, 210, 315, IIf((i = 2) Or (i = 5), 12, 10) * 210, 0, 210, 315
Next i
End Sub
Private Sub Timer1_Timer()
Dim cNow$, i&
cNow = Format(Now, "hh:mm:ss")
For i = 0 To 7
If Mid(cNow, i + 1, 1) <> ":" Then
picClock.PaintPicture picNumber.Picture, i * 210, 0, 210, 315, Val(Mid(cNow, i + 1, 1)) * 210, 0, 210, 315
End If
Next i
End Sub
望采纳
上面的代码错了,下面是正确代码
Private Sub Form_Load()
Timer1.Enabled = True
Timer1.Interval = 300
End Sub
Private Sub Timer1_Timer()
Label1 = Now
End Sub
第二部,添加一个计时器timer,一个文字标签label
第三部,输入代码,代码如下
Private Sub Form_Load()
picClock.Move (Me.ScaleWidth - 8 * 210) / 2, (Me.ScaleHeight - 315) / 2, 8 * 210, 315
Dim i&
For i = 0 To 7
picClock.PaintPicture picNumber.Picture, i * 210, 0, 210, 315, IIf((i = 2) Or (i = 5), 12, 10) * 210, 0, 210, 315
Next i
End Sub
Private Sub Timer1_Timer()
Dim cNow$, i&
cNow = Format(Now, "hh:mm:ss")
For i = 0 To 7
If Mid(cNow, i + 1, 1) <> ":" Then
picClock.PaintPicture picNumber.Picture, i * 210, 0, 210, 315, Val(Mid(cNow, i + 1, 1)) * 210, 0, 210, 315
End If
Next i
End Sub
望采纳
上面的代码错了,下面是正确代码
Private Sub Form_Load()
Timer1.Enabled = True
Timer1.Interval = 300
End Sub
Private Sub Timer1_Timer()
Label1 = Now
End Sub
参考资料: 葛军二级vb教程
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
'秒表要精确到毫秒级。要五个控件:两个标签,两个按钮,一个时钟,都用默认名字
Private Declare Function GetTickCount Lib "kernel32" () As Long
Private CanContinue As Boolean
Private Zsj As Long
Private i As Long
Private j As Long
Private Sub Command2_Click()
Label2 = "点击开始秒表运行"
Command2.Enabled = False
Command1.Caption = "开始"
Zsj = 0
i = 0
j = 0
End Sub
Private Sub Timer1_Timer()
'时钟
Label1.Caption = Time()
End Sub
Private Sub Form_Load()
Label1.Caption = Time()
Label2 = "点击开始秒表运行"
Command1.Caption = "开始"
Command2.Caption = "清除"
Command2.Enabled = False
End Sub
Private Sub Command1_click()
Command2.Enabled = True
If Command1.Caption = "暂停" Then
Command1.Caption = "继续"
CanContinue = False
Zsj = j - i
Else
Command1.Caption = "暂停"
i = GetTickCount() - Zsj
CanContinue = True
Do While CanContinue
j = GetTickCount()
a = (j - i) Mod 1000
b = Int((j - i) / 1000) Mod 60
c = Int((j - i) / 60000) Mod 60
d = Int((j - i) / 3600000) Mod 60
Label2 = d & ":" & c & ":" & b & "." & a
DoEvents
Loop
End If
End Sub
Private Declare Function GetTickCount Lib "kernel32" () As Long
Private CanContinue As Boolean
Private Zsj As Long
Private i As Long
Private j As Long
Private Sub Command2_Click()
Label2 = "点击开始秒表运行"
Command2.Enabled = False
Command1.Caption = "开始"
Zsj = 0
i = 0
j = 0
End Sub
Private Sub Timer1_Timer()
'时钟
Label1.Caption = Time()
End Sub
Private Sub Form_Load()
Label1.Caption = Time()
Label2 = "点击开始秒表运行"
Command1.Caption = "开始"
Command2.Caption = "清除"
Command2.Enabled = False
End Sub
Private Sub Command1_click()
Command2.Enabled = True
If Command1.Caption = "暂停" Then
Command1.Caption = "继续"
CanContinue = False
Zsj = j - i
Else
Command1.Caption = "暂停"
i = GetTickCount() - Zsj
CanContinue = True
Do While CanContinue
j = GetTickCount()
a = (j - i) Mod 1000
b = Int((j - i) / 1000) Mod 60
c = Int((j - i) / 60000) Mod 60
d = Int((j - i) / 3600000) Mod 60
Label2 = d & ":" & c & ":" & b & "." & a
DoEvents
Loop
End If
End Sub
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
百度上,多学习学习,会编出来的。
如果我帮你的话,收费服务,10块人民币给你编好。有售后的。
如果我帮你的话,收费服务,10块人民币给你编好。有售后的。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
控件:Text1(文本框)、Timer(定时器)
Private Sub Form_Load()
Text1.Text = Time()
Timer1.Interval = 1000
End Sub
Private Sub Timer1_Timer()
Text1.Text = Time()
End Sub
Private Sub Form_Load()
Text1.Text = Time()
Timer1.Interval = 1000
End Sub
Private Sub Timer1_Timer()
Text1.Text = Time()
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
'在窗体添加控件:Timer1、Label1
Private Sub Form_Load()
Timer1.Interval = 500: Timer1.Enabled = True
Label1.Font.Size = 48: Label1.AutoSize = True
End Sub
Private Sub Timer1_Timer()
Label1.Caption = Format(Now, "hh:mm:ss")
End Sub
Private Sub Form_Load()
Timer1.Interval = 500: Timer1.Enabled = True
Label1.Font.Size = 48: Label1.AutoSize = True
End Sub
Private Sub Timer1_Timer()
Label1.Caption = Format(Now, "hh:mm:ss")
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询