Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.basic.visual.misc > #1818
| From | "Nobody" <nobody@nobody.com> |
|---|---|
| Newsgroups | comp.lang.basic.visual.misc |
| Subject | Re: Decrementing a countdown timer |
| Date | 2011-02-08 14:24 -0500 |
| Organization | Aioe.org NNTP Server |
| Message-ID | <iis59u$8tv$1@speranza.aioe.org> (permalink) |
| References | <3663fbde-259b-4a32-bcdb-eecba2086825@l11g2000yqb.googlegroups.com> |
"jason@smkzone.com" <jbodine1@yahoo.com> wrote in message
news:3663fbde-259b-4a32-bcdb-eecba2086825@l11g2000yqb.googlegroups.com...
> Hi all,
>
> The following code displays a static time in lblPPTimer, but I need it
> to decrement the days, hours, minutes, and seconds. Tried adding -1
> to all the values, but all that does is take the static time down by
> one. The interval for timer2 is set to 1000. How do I make it show
> the countdown?
>
> Public Sub PPTimer()
> Dim tStart As Date
> Dim tEnd As Date
> tStart = GetSetting(App.ProductName, "Pay Period", "Start Date")
> tEnd = GetSetting(App.ProductName, "Pay Period", "End Date")
> With frmTimeClock
> With .Timer2
> Dim tNow As Date
> Dim Days As Long
> Dim Hours As Long
> Dim Minutes As Long
> Dim Seconds As Long
>
> tNow = Now
>
> If tNow = tEnd Then
> frmTimeClock.lblPPTimer.Caption = "Time Remaining: 00d:00h:
> 00m:00s"
> frmTimeClock.lblPPTimer.ForeColor = vbRed
> MsgBox "Time Elapsed! Click OK to end the Current Pay
> Period!", vbOKOnly, "Reminder!"
> EndCurrPP
> .Enabled = False
> Exit Sub
> Else
> Seconds = DateDiff("s", tStart, tEnd)
> Minutes = Seconds \ 60
> Seconds = Seconds - Minutes * 60
> Hours = Minutes \ 60
> Minutes = Minutes - Hours * 60
> Days = Hours \ 24
> Hours = Hours - Days * 24
> frmTimeClock.lblPPTimer.Caption = "Time Remaining: " & _
> Format$(Days) & "d:" & _
> Format$(Hours) & "h:" & _
> Format$(Minutes) & "m:" & _
> Format$(Seconds) & "s"
>
> End If
> End With
> End With
Use DateAdd() function with negative numbers. Also, use Second(), Minute(),
Hour(), Day(), Month(), Year() functions to get the parts that you want, or
use DatePart function. When extracting the information, don't use Now as the
input to the function, but use a variable, because calling Now multiple
times could give different results. Example:
Dim dNow As Date
dNow = Now
Debug.Print Second(dNow)
Debug.Print Minute(dNow)
Debug.Print Hour(dNow)
Back to comp.lang.basic.visual.misc | Previous | Next — Next in thread | Find similar | Unroll thread
Re: Decrementing a countdown timer "Nobody" <nobody@nobody.com> - 2011-02-08 14:24 -0500 Re: Decrementing a countdown timer "Mike Williams" <Mike@WhiskyAndCoke.com> - 2011-02-08 22:09 +0000 Re: Decrementing a countdown timer "jason@smkzone.com" <jbodine1@yahoo.com> - 2011-02-08 13:13 -0800
csiph-web