I want to make a countdown time that will basically let you click one of the buttons and the countdown will start. But I don’t want the countdown to be shown in seconds but rather in Hours/Minutes/Seconds. There will be multiple buttons that will trigger the countdown. The only hiccup that I can see that the countdown for some of the buttons it’s not just a fixed time it’s a range i.e. 45mins-1hr. Is there a code out there that will let me do that? Or at least a code that will just do a straight countdown and maybe at a certain point from its countdown there can be a warning. i.e. countdown starts from 2hrs..45mins have passed, countdown continues but a pop up will appear or something to that affect letting you know 45mins have passed. Also I don’t know if it’s possible but when the countdown ends I want something to be said, I’m not sure what yet but I would have a better idea on what I would want it to be knowing if I could do it as easy as adding in a mp3 clip or you type it and the computer will read it out like Microsoft Sam.

Sorry if this all seems jumbled and confusing to you just tell me and I will clarify what is confusing to you.

also this is in the VB section and I am using VB 6.


~Xjmas

Recommended Answers

All 11 Replies

Use something as below. Modify it to suit what you need. Just add the controls as required -

Dim Hours As Integer
Dim Minutes As Integer
Dim Seconds As Integer
Dim Time As Date
Private Sub Mydisplay()
'This code is common to all three text boxes so I
'put it in it's own sub.

'Extract the numbers from the text boxes by using
'the Val() statement.
    Hours = Val(Text1.Text)
    Minutes = Val(Text2.Text)
    Seconds = Val(Text3.Text)
'Convert variables to time format
    Time = TimeSerial(Hours, Minutes, Seconds)
'Display the converted time variable in label 1
    Label1.Caption = Format$(Time, "hh") & ":" & Format$(Time, "nn") & ":" & Format$(Time, "ss")
End Sub

Private Sub Command1_Click()
'Start button - turn on timer and disable reset
'button
    Timer1.Enabled = True
    Command3.Enabled = False
End Sub

Private Sub Command2_Click()
'Pause button - temporarily stop timer and enable
'reset button. You can restart countdown by clicking
'the start button. Or reset the time by clicking
'the reset button.
    Timer1.Enabled = False
    Command3.Enabled = True
End Sub

Private Sub Command3_Click()
'Reset button - reset all varibles and text boxes
'to nothting.
    Hours = 0
    Minutes = 0
    Seconds = 0
    Time = 0
    Text1.Text = " "
    Text2.Text = " "
    Text3.Text = " "
    Text1.SetFocus 'put curser in the hour text box
End Sub

Private Sub Command4_Click()
'Exit button - end program and clear varibles
    End
End Sub

Private Sub Form_Load()
'Center form on screen.
Form1.Top = (Screen.Height - Form1.Height) / 2
Form1.Left = (Screen.Width - Form1.Width) / 2
'Set timer interval and varibles
    Timer1.Interval = 1000
    Hours = 0
    Minutes = 0
    Seconds = 0
    Time = 0
End Sub

Private Sub Text1_Change()
'Call Mydisplay sub to display text box data
    Mydisplay
End Sub

Private Sub Text2_Change()
'Call Mydisplay sub to display text box data
    Mydisplay
End Sub

Private Sub Text3_Change()
'Call Mydisplay sub to display text box data
    Mydisplay
End Sub

Private Sub Timer1_Timer()
    'Count down loop
    Timer1.Enabled = False
    If (Format$(Time, "hh") & ":" & Format$(Time, "nn") & ":" & Format$(Time, "ss")) <> "00:00:00" Then 'Counter to continue loop until 0
        Time = DateAdd("s", -1, Time)
        Label1.Visible = False
        Label1.Caption = Format$(Time, "hh") & ":" & Format$(Time, "nn") & ":" & Format$(Time, "ss")
        Label1.Visible = True
        Timer1.Enabled = True
    Else
        'Turn off timer, set off alarm, and enable reset.
        Timer1.Enabled = False
        Beep
        Beep
        Command3.Enabled = True
    End If
End Sub

Thank You. I will give this a whirl today and come back to share the outcome.

~Xjmas

No problem.:)

Private Sub Mydisplay()

how exactly do i get to this?. i figured it'd be like finding the private sub Form_Load() but not at all.

Private Sub Mydisplay()

how exactly do i get to this?. i figured it'd be like finding the private sub Form_Load() but not at all.

Figured it out just typed it in.

Sorry, had an off weekend.:)

Did the above solve your problem?

That's alright. Yes it did solve my problem I'm going to continue working on my little project up until friday i know i will have a few hiccups going through it so i can change the code to benefit me and what i am doing. Would it be ok if i posted here again after Christmas holidays?

Of course it is (posting after Christmas, depending on whether we are online):)

Please mark this thread as solved, found at the bottom of this page, thanks.:)

Using this code i made a Command button on the main form called Program. What im trying to do is make another form appaer that will have the 3 text box's the Start command button that once clicked it will return to the main form with the countdown started.
this is the from frm1

Private Sub cmdprogram_Click()
frm2.Show 1
End Sub

and frm2

Private Sub cmdstart_Click()
'Start button - turn on timer and disable reset
'button
Unload frm2
Timer1.Enabled = True
cmdReset.Enabled = False
End Sub

Private Sub MyDisplay()
'This code is common to all three text boxes so
'put it in it's own sub
'Extract the numbers from the text boxes by using
'the Val() statement.
Hours = Val(txthour.Text)
Minutes = Val(txtmin.Text)
Seconds = Val(txtsec.Text)
'Convert variables to time format
Time = TimeSerial(Hours, Minutes, Seconds)
'Display the converted time variable in label 1
lblScreen.Caption = Format$(Time, "hh") & ":" & Format$(Time, "nn") & ":" & Format$(Time, "ss")
End Sub

Private Sub txthour_Change()
'Call Mydisplay sub to display text box data
MyDisplay
End Sub

Private Sub txtmin_Change()
'Call Mydisplay sub to display text box data
MyDisplay
End Sub

Private Sub txtsec_Change()
'Call Mydisplay sub to display text box data
MyDisplay
End Sub

i have it switching to the second form fine. but as soon as i type a number into a text box i get a run-time error 424. When i hit Debug this line is highlighted.

'Convert variables to time format
Time = TimeSerial(Hours, Minutes, Seconds)

Using this code i made a Command button on the main form called Program. What im trying to do is make another form appaer that will have the 3 text box's the Start command button that once clicked it will return to the main form with the countdown started.
this is the from frm1

Private Sub cmdprogram_Click()
frm2.Show 1
End Sub

and frm2

Private Sub cmdstart_Click()
'Start button - turn on timer and disable reset
'button
Unload frm2
Timer1.Enabled = True
cmdReset.Enabled = False
End Sub

Private Sub MyDisplay()
'This code is common to all three text boxes so
'put it in it's own sub
'Extract the numbers from the text boxes by using
'the Val() statement.
Hours = Val(txthour.Text)
Minutes = Val(txtmin.Text)
Seconds = Val(txtsec.Text)
'Convert variables to time format
Time = TimeSerial(Hours, Minutes, Seconds)
'Display the converted time variable in label 1
lblScreen.Caption = Format$(Time, "hh") & ":" & Format$(Time, "nn") & ":" & Format$(Time, "ss")
End Sub

Private Sub txthour_Change()
'Call Mydisplay sub to display text box data
MyDisplay
End Sub

Private Sub txtmin_Change()
'Call Mydisplay sub to display text box data
MyDisplay
End Sub

Private Sub txtsec_Change()
'Call Mydisplay sub to display text box data
MyDisplay
End Sub

i have it switching to the second form fine. but as soon as i type a number into a text box i get a run-time error 424. When i hit Debug this line is highlighted.

'Convert variables to time format
Time = TimeSerial(Hours, Minutes, Seconds)

Edit: For the past while i've been trying to use this code in a way that helps me and trying to modify it also. but i can't seem to make it work the way i want to. i want there to only be one command button and when you click that button the time would appear on the command button by using Command1.enabled instead of having it appear on the label. but the next problem that was in the way was removing the text boxes and just already having the set time in the code so the countdown can start from there. Are you able to help me with that?

Of course we can assist you, that is what we are here for.:)

I do however need you to open a new thread with a specific question because this thread has been closed already. I'm not sure what it is exactly that you require however, be a bit more specific, sorry.

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.