1、添加一个“label控件”命名为label
2、添加一个“timer控件”命名为timer1
3、设置“timer1”的“Interval属性”为1000
使用到的代码:
Dim Hour As Integer '小时Dim Min As Integer '分钟
Dim Sec As Integer '秒
Private Sub Form_Load()
Hour = 0
Min = 0
Sec = 0
Label1.Caption = "00 : 00 : 00"
End Sub
Private Sub Timer1_Timer()
Dim strHour As String
Dim strMin As String
Dim strSec As String
Sec = Sec + 1
If Sec >= 60 Then
Sec = 0
Min = Min + 1
If Min >= 60 Then
Min = 0
Hour = Hour + 1
If Hour >= 24 Then
Hour = 0
End If
End If
End If
If Hour < 10 Then
strHour = "0" & Hour
Else
strHour = Hour
End If
If Min < 10 Then
strMin = "0" & Min
Else
strMin = Min
End If
If Sec < 10 Then
strSec = "0" & Sec
Else
strSec = Sec
End If
Label1.Caption = strHour & " : " & strMin & " : " & strSec
End Sub
Private Sub Form_Load()Timer1.Interval = 1000
Timer1.Enabled = True
End Sub
Private Sub Timer1_Timer()
Text1 = Year(Now)
Text2 = Month(Now)
Text3 = Day(Now)
Text4 = Time
End Sub
做一个简单的闹钟程序很简单的。我这里不用if语句。首先我们在窗体上添加一个标签控件,再画一个“闹钟”,将闹钟得interval属性改为1000,双击闹钟,进入闹钟的代码视图,编写代码private
sub
timer1_timer()
label1.caption
=
time
end
sub就行了。谢谢采纳
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)