That same ole' timer question

computermom

New member
Joined
Apr 16, 2006
Messages
2
Programming Experience
1-3
Hi everyone....I am new here and I have a question concerning ....timers:eek:
Anyway, I have searched the forums to see if my question had already been answered so I would not worry anyone with the same ole timer question. I am creating a timer in vb.net using a timer class. I have also created a windows form that has a label that outputs the time in min:sec. The form also has a minute btn, a second btn, a stop btn, start btn and a clear btn. I have coded my minute, second btns. I am having problems with my start button. What I want to happen when I click the start button is I want the timer to decrement time. Say for instance, if the timer has 2:00, it will decrement to 1:59 all the way until it gets to 0. When it gets to zero, and there is no more time, the time stops. I notice in some of the discussions a system.timer was used. I don't want to use this, just manual coding. I have created a procedure called "decrementtime" that when the seconds=0 then the minutes will subtract 1. But in my program code, when it reaches say for instance :59 and start decrement all the way down to zero, it starts decrementing again at :59. I am not sure where my problem lies, but any information and help on this will be much appreciated. I apologize for the "same ole timer question".:eek:
computermom
 
Hi These are the procedures I am using in my Timer class. I am wanting to be able to accept up to 99 minutes. When my start button is clicked, I am wanting the time to start decrementing from whatever the start time is in seconds and minutes. For instance if 3:00 is input, then the timer starts at 2:59 until both minutes and seconds is 00:00 and the timer stops. What I have, the time decrements, but when it start decrementing at 00:59 down to :00, it starts over again at 00:59, while the minutes remain at 00, and I am unsure how to make the timer stop when minutes and seconds is 00:00.
I hope you can understand what I am trying to do, and the problems I am having.
thanks
computermom:)

Public
Sub decrementMinute()
If Minutes <= 99 Then
Minutes = Minutes - 1
Else
Seconds = Seconds - 1
EndIf
EndSub
PublicSub decrementSecond()
If Seconds <= 60 Then
Seconds = Seconds - 1
Else
decrementMinute()
EndIf
EndSub
PublicSub decrementTime()
decrementSecond()
If Seconds = 0 Then
Seconds = 59 - Seconds
Minutes = Minutes - 1
EndIf
EndSub
 
Is this close to what you want?

VB.NET:
    Public Sub decrementTime()
        If seconds = 0 Then
            If minutes = 0 Then
                [COLOR=SeaGreen]'do nothing time is at 00:00[/COLOR]
            Else
                minutes -= 1
            End If
        Else
            seconds -= 1
        End If
    End Sub
Upon close inspection, I think what you want is a coundown timer. Research the timespan class.
 
Last edited:
Back
Top