如何用VB TIMER 和TEXTBOS做一个时间倒计时并在TEXT里显示这个时间
2个回答
展开全部
Private Sub Command1_Click()
Timer1.Interval = 1000
Dim mh As Integer '冒号所在文本框中的位置
Dim fenzhong As String
Dim miao As String
mh = InStr(1, Trim(Text1.Text), ":") '查找文本框中冒号的位置,设定时设定文本框内的时间为分钟如:10:00代表十分钟,120:00代表两小时。
fenzhong = Mid(Trim(Text1.Text), 1, mh - 1)
miao = Mid(Trim(Text1.Text), mh + 1, Len(Trim(Text1.Text)) - mh)
End Sub
Private Sub Command2_Click()
Timer1.Interval = 0
End Sub
Private Sub Timer1_Timer()
Dim mh As Integer '冒号所在文本框中的位置
Dim fenzhong As String
Dim miao As String
mh = InStr(1, Trim(Text1.Text), ":") '查找文本框中冒号的位置,设定时设定文本框内的时间为分钟如:10:00代表十分钟,120:00代表两小时。
fenzhong = Mid(Trim(Text1.Text), 1, mh - 1)
miao = Mid(Trim(Text1.Text), mh + 1, Len(Trim(Text1.Text)) - mh)
'开始倒计时
If Val(miao) - 1 <= 0 Then
miao = "59"
Else
miao = Trim(Str((Val(miao) - 1)))
If Len(miao) = 1 Then
miao = "0" & miao
Else
miao = miao
End If
End If
If miao = "00" Or miao = "59" Then
fenzhong = Trim(Str(Val(fenzhong) - 1))
If fenzhong < 0 Then
Timer1.Interval = 0
Text1.Text = "00:00"
Exit Sub
Else
fenzhong = fenzhong
End If
End If
Text1.Text = fenzhong & ":" & miao
End Sub
以上代码调试通过,希望能帮到你!
Timer1.Interval = 1000
Dim mh As Integer '冒号所在文本框中的位置
Dim fenzhong As String
Dim miao As String
mh = InStr(1, Trim(Text1.Text), ":") '查找文本框中冒号的位置,设定时设定文本框内的时间为分钟如:10:00代表十分钟,120:00代表两小时。
fenzhong = Mid(Trim(Text1.Text), 1, mh - 1)
miao = Mid(Trim(Text1.Text), mh + 1, Len(Trim(Text1.Text)) - mh)
End Sub
Private Sub Command2_Click()
Timer1.Interval = 0
End Sub
Private Sub Timer1_Timer()
Dim mh As Integer '冒号所在文本框中的位置
Dim fenzhong As String
Dim miao As String
mh = InStr(1, Trim(Text1.Text), ":") '查找文本框中冒号的位置,设定时设定文本框内的时间为分钟如:10:00代表十分钟,120:00代表两小时。
fenzhong = Mid(Trim(Text1.Text), 1, mh - 1)
miao = Mid(Trim(Text1.Text), mh + 1, Len(Trim(Text1.Text)) - mh)
'开始倒计时
If Val(miao) - 1 <= 0 Then
miao = "59"
Else
miao = Trim(Str((Val(miao) - 1)))
If Len(miao) = 1 Then
miao = "0" & miao
Else
miao = miao
End If
End If
If miao = "00" Or miao = "59" Then
fenzhong = Trim(Str(Val(fenzhong) - 1))
If fenzhong < 0 Then
Timer1.Interval = 0
Text1.Text = "00:00"
Exit Sub
Else
fenzhong = fenzhong
End If
End If
Text1.Text = fenzhong & ":" & miao
End Sub
以上代码调试通过,希望能帮到你!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Private Sub Command1_Click()
Timer1.Enabled = True
End Sub
Private Sub Command2_Click()
Timer1.Enabled = False
End Sub
Private Sub Form_Load()
Timer1.Enabled = False
Timer1.Interval = 1000
Text1.Text = "00:01:00"
End Sub
Private Sub Timer1_Timer()
Text1.Text = DateAdd("S", -1, Text1.Text)
If Text1.Text = "00:00:00" Then
MsgBox "time out"
Timer1.Enabled = False
End If
End Sub
Timer1.Enabled = True
End Sub
Private Sub Command2_Click()
Timer1.Enabled = False
End Sub
Private Sub Form_Load()
Timer1.Enabled = False
Timer1.Interval = 1000
Text1.Text = "00:01:00"
End Sub
Private Sub Timer1_Timer()
Text1.Text = DateAdd("S", -1, Text1.Text)
If Text1.Text = "00:00:00" Then
MsgBox "time out"
Timer1.Enabled = False
End If
End Sub
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询