Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

timer

Status
Not open for further replies.

jagnval

Technical User
Feb 19, 2009
10
0
0
US
Ihave have found this code that work of the ontimer property on a form and was wondering hw to make it STOP when it reaches 0, as of now it starts counting again after it reaches zero, please help thanks,

Function YMWDHMS(ByVal SecondsIn As Variant) As String
Dim TempDate As Date
Dim Date1 As Date
Dim Date2 As Date
Dim NumOfMonths As Long
Dim NumOfWeeks As Long
Dim NumOfDays As Long
Dim NumOfHMS As Double
Dim TSerial1 As Double
Dim TSerial2 As Double
Date2 = Now
Date1 = DateAdd("s", -SecondsIn, Date2)
NumOfYears = DateDiff("yyyy", Date1, Date2)
TSerial1 = TimeSerial(Hour(Date1), Minute(Date1), Second(Date1))
TSerial2 = TimeSerial(Hour(Date2), Minute(Date2), Second(Date2))
NumOfHMS = 24 * (TSerial2 - TSerial1)
If NumOfHMS < 0 Then
NumOfHMS = NumOfHMS + 24
Date2 = DateAdd("d", -1, Date2)
End If
NumOfDays = Abs(DateDiff("d", Date1, Date2))
NumOfWeeks = NumOfDays \ 7
NumOfDays = NumOfDays Mod 7
' Format the Years, Months, Weeks, Days part
YMWDHMS = YMWDHMS & CStr(NumOfWeeks) & _
" week" & IIf(NumOfWeeks = 1, "", "s ")
YMWDHMS = YMWDHMS & " "
YMWDHMS = YMWDHMS & CStr(NumOfDays) & _
" day" & IIf(NumOfDays = 1, "", "s ")
' Format the Hours, Minutes and Seconds part
YMWDHMS = YMWDHMS & " "
YMWDHMS = YMWDHMS & CStr(Int(NumOfHMS)) & _
" Hour" & IIf(Int(NumOfHMS) = 1, "", "s ")
NumOfHMS = 60 * (NumOfHMS - Int(NumOfHMS))
YMWDHMS = YMWDHMS & " "
YMWDHMS = YMWDHMS & CStr(Int(NumOfHMS)) & _
" Minute" & IIf(Int(NumOfHMS) = 1, "", "s ")
NumOfHMS = 60 * (NumOfHMS - Int(NumOfHMS))
YMWDHMS = YMWDHMS & " "
YMWDHMS = YMWDHMS & CStr(CInt(NumOfHMS)) & _
" second" & IIf(Int(NumOfHMS) = 1, "", "s")
End Function
 



Hi,

What you posted is NOT a timer.

Rather it is a function that converts a value of SECONDS into weeks, days, hours, minutes and seconds.

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 



Don't call it!

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top