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()Me.Caption = "数字时钟"
Timer1.Interval = 1000
Timer1.Enabled = True
End Sub
Private Sub Timer1_Timer()
Label1.Caption = Format(Now, "yyyy年m月d日")
Label2.Caption = Format(Now, "hh时nn分ss秒")
End Sub
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)