主题:[讨论]Vb6 计时倒数问题 (问题已解决)
Vb6 计时倒数问题
最近在网上找到了一个计时倒数, 发觉实用性不错,想自行加以运用,却发现一个问题,请各大大指教。
这个定时器用command1 开动,Label1是显示时间,倒数6秒后会有MsgBox,
我自己加了一个command 2去暂停。
举一个例子,6秒开始倒数,还有4秒的时候我按command2暂停了,Label1显示时间还剩余4秒,之后等了3秒后我再按command1去开动暂停了的计时,Label1显示1秒。
请问如果我想在等了3秒后我再按command1去开动暂停了的计时,Label1是继续显示4秒,并从剩余的4秒开始继续倒数,应该要怎样写?
Option Explicit
Private Declare Function GetTickCount Lib "kernel32" () As Long
Public TimeStart As Long
Public TimeEnd As Long
Private Sub Command1_Click()
Timer1.Enabled = Not Timer1.Enabled
If Timer1.Enabled Then
TimeEnd = 6000
TimeStart = GetTickCount
End If
End Sub
Private Sub Command2_Click()
Timer1.Enabled = Not Timer1.Enabled
End Sub
Private Sub Form_Load()
Timer1.Interval = 100
Timer1.Enabled = False
End Sub
Private Sub Timer1_Timer()
Dim CountTime As Long
CountTime = GetTickCount - TimeStart
If CountTime > TimeEnd Then
Timer1.Enabled = False
MsgBox "time's up!"
Else
Label1.Caption = FormatTime(TimeEnd - CountTime)
End If
End Sub
Private Function FormatTime(ft_Time As Long) As String
Dim i As Long, j As Long
i = ft_Time \ 1000
j = ft_Time \ 100
FormatTime = Format(i \ 3600, "00:") & Format((i Mod 3600) \ 60, "00:") & Format(i Mod 60, "00.") & Format(j Mod 10, "0")
End Function
最近在网上找到了一个计时倒数, 发觉实用性不错,想自行加以运用,却发现一个问题,请各大大指教。
这个定时器用command1 开动,Label1是显示时间,倒数6秒后会有MsgBox,
我自己加了一个command 2去暂停。
举一个例子,6秒开始倒数,还有4秒的时候我按command2暂停了,Label1显示时间还剩余4秒,之后等了3秒后我再按command1去开动暂停了的计时,Label1显示1秒。
请问如果我想在等了3秒后我再按command1去开动暂停了的计时,Label1是继续显示4秒,并从剩余的4秒开始继续倒数,应该要怎样写?
Option Explicit
Private Declare Function GetTickCount Lib "kernel32" () As Long
Public TimeStart As Long
Public TimeEnd As Long
Private Sub Command1_Click()
Timer1.Enabled = Not Timer1.Enabled
If Timer1.Enabled Then
TimeEnd = 6000
TimeStart = GetTickCount
End If
End Sub
Private Sub Command2_Click()
Timer1.Enabled = Not Timer1.Enabled
End Sub
Private Sub Form_Load()
Timer1.Interval = 100
Timer1.Enabled = False
End Sub
Private Sub Timer1_Timer()
Dim CountTime As Long
CountTime = GetTickCount - TimeStart
If CountTime > TimeEnd Then
Timer1.Enabled = False
MsgBox "time's up!"
Else
Label1.Caption = FormatTime(TimeEnd - CountTime)
End If
End Sub
Private Function FormatTime(ft_Time As Long) As String
Dim i As Long, j As Long
i = ft_Time \ 1000
j = ft_Time \ 100
FormatTime = Format(i \ 3600, "00:") & Format((i Mod 3600) \ 60, "00:") & Format(i Mod 60, "00.") & Format(j Mod 10, "0")
End Function