hey y'all

i just started messing with VB about 3 days ago

i just created a countdown timer.
it works as far as result goes
but here's my prob.
i created a command button, when i click on it, it shows me the correct countdown and all

how can i keep the app runnin and the screen refreshing every
second on its own.

i want it to constantly update itself in 1 sec increments without me doing anything


any help?? thanks

Dani AI

Generated

A few practical points that tie together the suggestions from , and and the "stops for a while" symptom reported.

VB6 Timer is message‑based and runs on the UI thread, so it can be delayed whenever your app is busy (long loops, database calls, Sleep, heavy painting). That makes simple decrementing counters drift or appear to "stop". A robust approach is to record an absolute target time when the countdown starts and, on each tick, compute the remaining seconds from the system clock — that way missed ticks are accounted for and the display never accumulates error.

Example pattern (start once, then update each tick):

' set targetTime when countdown begins
Dim targetTime As Date
targetTime = DateAdd("s", 300, Now)  ' example: 5 minutes from now

' in Timer event (tick ~ once per second)
Dim secs As Long
secs = DateDiff("s", Now, targetTime)
If secs <= 0 Then
  lblTime.Caption = "00:00:00"
  Timer1.Enabled = False
  MsgBox "Done"
Else
  ' compute H:M:S from secs and update label
  lblTime.Caption = Format$(Int(secs/3600), "00") & ":" & _
                    Format$((secs \ 60) Mod 60, "00") & ":" & _
                    Format$(secs Mod 60, "00")
  lblTime.Refresh
End If

Troubleshooting tips: do not put long/blocking operations inside the Timer event; move heavy processing off the UI thread (background process or async calls). Use control.Refresh or form.Repaint after setting captions to force an immediate redraw. Prefer enabling the timer after initialization rather than manually calling the Timer routine from Form_Load (that can hide timing problems). If you need sub‑second precision for animations or high‑accuracy timing, consider platform timers or a separate worker thread — but for a simple countdown the target‑time + DateDiff approach is reliable and prevents drift.

Recommended Answers

All 7 Replies

Hi ,

Take a look at this app. It might be helpful to you.

wow, thank you very much!!!!!

Hi ,

Take a look at this app. It might be helpful to you.

thanks for the info... i used your timer in one of the system i created, at first it was ok, but when i turn my system, the timer seems creating a delay... it stops for a while for a reason i dont know. please help me with this... thanks a lot

call the procedure timer1_timer under form_load event.

thank you so much....it helps a lot...

how about an actual time?

To use actual time; you need to use a timer with 1000 millisecond interval, if we use the variables THour, TMinute, TSecond for Alarm time then the code will be:

Private Sub Timer1_Timer()
If Hour(Time) = THour AND Minute(Time) = TMinute AND Second(Time) = TSecond THEN 
Msgbox "Alarm!" 'or whatever you want to do 
End IF
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.