Results 1 to 13 of 13

Thread: Count Down Help..

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jan 2005
    Location
    Georgia
    Posts
    18

    Count Down Help..

    How do I make a label countdown, from data from another form, where you input a number in a text box, The number equaling Minutes. and the countdown in HH:MM:SS format..

  2. #2
    New Member
    Join Date
    Jan 2005
    Posts
    11

    Re: Count Down Help..


  3. #3
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: Count Down Help..

    Here si a quicky for you TT:
    you will need a Command button, Timer and Label to run sample.
    VB Code:
    1. Option Explicit
    2.  
    3. Dim lngMinutes As Long
    4.  
    5. Private Sub Command1_Click()
    6. Dim strMinutes$, sTime$
    7.  
    8.     strMinutes = InputBox("Type number of minutes.", "Countdown", "60")
    9.     If Not IsNumeric(strMinutes) Then
    10.         MsgBox "Cannot begin count down - invalid number."
    11.         Exit Sub
    12.     Else
    13.         lngMinutes = CLng(strMinutes)
    14.     End If
    15.    
    16.     sTime = Str$(lngMinutes * 60 \ 3600) & " hours " & _
    17.             Str$(lngMinutes * 60 Mod 60) & " minutes " & _
    18.             Str$(lngMinutes * 60 Mod 60) & " seconds "
    19.     Label1.Caption = sTime
    20.     Timer1.Enabled = True
    21.     Timer1.Interval = 60000 '1 minute
    22.  
    23. End Sub
    24.  
    25. Private Sub Form_Load()
    26.     Timer1.Enabled = False
    27. End Sub
    28.  
    29. Private Sub Timer1_Timer()
    30. Dim sTime$
    31. Static lSeconds&
    32.  
    33.     lngMinutes = lngMinutes - 60
    34.     lSeconds = lngMinutes * 60
    35.     sTime = Str$(lSeconds \ 3600) & " hours " & _
    36.             Str$(lSeconds \ 60) & " minutes " & _
    37.             Str$(lSeconds Mod 60) & " seconds "
    38.     Label1.Caption = sTime
    39.  
    40. End Sub

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Jan 2005
    Location
    Georgia
    Posts
    18

    Re: Count Down Help..

    hey thanks for the reply, i tested it and for 60 mins.. Says 1 hour then goes to 0, then nothin happens lol :x how i would i get it to say the seconds as they pass...

  5. #5
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: Count Down Help..

    That is only a sample and you should have tried to work it out but here is another (modified) "version":
    VB Code:
    1. Option Explicit
    2.  
    3. Dim lngMinutes As Long
    4.  
    5. Private Sub Command1_Click()
    6. Dim strMinutes$, sTime$
    7.  
    8.     strMinutes = InputBox("Type number of minutes.", "Countdown", "60")
    9.     If Not IsNumeric(strMinutes) Then
    10.         MsgBox "Cannot begin count down - invalid number."
    11.         Exit Sub
    12.     Else
    13.         lngMinutes = CLng(strMinutes)
    14.     End If
    15.    
    16.     sTime = Str$(lngMinutes \ 60) & " hours " & _
    17.             Str$(lngMinutes Mod 60) & " minutes " & _
    18.             Str$(lngMinutes * 60 Mod 60) & " seconds "
    19.     Label1.Caption = sTime
    20.     Timer1.Enabled = True
    21.     Timer1.Interval = 1000 '1 second
    22.  
    23. End Sub
    24.  
    25. Private Sub Form_Load()
    26.     Timer1.Enabled = False
    27. End Sub
    28.  
    29. Private Sub Timer1_Timer()
    30. Dim sTime$
    31. Static lSeconds&
    32.  
    33.     If lSeconds = 0 Then
    34.         lSeconds = lngMinutes * 60
    35.         sTime = Str$(lSeconds Mod 3600) & " hours " & _
    36.                 Str$(lSeconds \ 60) & " minutes " & _
    37.                 Str$(lSeconds Mod 60) & " seconds "
    38.     Else
    39.         lSeconds = lSeconds - 1
    40.         sTime = Str$(lSeconds \ 3600) & " hours " & _
    41.                 Str$(lSeconds \ 60) & " minutes " & _
    42.                 Str$(lSeconds Mod 60) & " seconds "
    43.     End If
    44.    
    45.     Label1.Caption = sTime
    46.     If lSeconds = 0 Then Timer1.Enabled = False
    47.  
    48. End Sub

  6. #6
    Addicted Member VbMafia's Avatar
    Join Date
    Sep 2004
    Location
    Pilipinas
    Posts
    177

    Re: Count Down Help..

    This the answer

    VB Code:
    1. Label1.Caption=format(time, "hh:mm:ss"

    Set the interval to 1000
    " I never did anything worth doing entirely by accident.... Almost none of my inventions were derived in that manner. They were achieved by having trained myself to be analytical and to endure and tolerate hard work."

    " Many of life's failures are experienced by people who did not realize how close they were to success when they gave up. "
    - Thomas Alva Edison-

    In God We Trust

  7. #7
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: Count Down Help..

    That would just give you a current system time which isn't what TrueThreat asked for: he needs to begin a countdown from a given point (say 40 minutes left, then 39 min and 57 seconds and so on ...)

  8. #8
    Addicted Member VbMafia's Avatar
    Join Date
    Sep 2004
    Location
    Pilipinas
    Posts
    177

    Re: Count Down Help..

    Sorry RhinoBull i thought that is code..
    " I never did anything worth doing entirely by accident.... Almost none of my inventions were derived in that manner. They were achieved by having trained myself to be analytical and to endure and tolerate hard work."

    " Many of life's failures are experienced by people who did not realize how close they were to success when they gave up. "
    - Thomas Alva Edison-

    In God We Trust

  9. #9
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: Count Down Help..

    You don't have to be sorry - I don't have any problem with someone's trying to help.

  10. #10

    Thread Starter
    Junior Member
    Join Date
    Jan 2005
    Location
    Georgia
    Posts
    18

    Re: Count Down Help..

    ok it works good, thanks but theres a slight problem, i want it in the format hh:mm:ss, which i got it, but like 01:00:00 then it goes to 00:60:00 lol so its like 60 mins + an extra second, why is it doing this? :x thanks again for the help

  11. #11

    Thread Starter
    Junior Member
    Join Date
    Jan 2005
    Location
    Georgia
    Posts
    18

    Re: Count Down Help..

    bump.. lol why does it go from 01:00:00 to 01:60:00 then 00:59:00 when it should go straight to 59..

  12. #12
    Fanatic Member vbasicgirl's Avatar
    Join Date
    Jan 2004
    Location
    Manchester, UK
    Posts
    1,016

    Re: Count Down Help..

    heres a different approach.
    VB Code:
    1. Option Explicit
    2. Private secs As Long
    3.  
    4. Private Sub Form_Load()
    5.  Timer1.Enabled = False
    6.  Timer1.Interval = 1000
    7. End Sub
    8.  
    9. Private Sub Command1_Click()
    10.  Dim inp As String
    11.  
    12.   inp = InputBox("Enter number of minutes", "Countdown")
    13.     If IsNumeric(inp) Then
    14.        secs = Val(inp) * 60
    15.        Timer1.Enabled = True
    16.     Else
    17.        MsgBox "Must be numeric", vbInformation, "Error"
    18.     End If
    19. End Sub
    20.  
    21. Private Sub Timer1_Timer()
    22.  Label1.Caption = CDate(secs / 86400)
    23.  secs = secs - 1
    24.  
    25.  If secs < 0 Then
    26.   Timer1.Enabled = False
    27.  End If
    28. End Sub

    casey.

  13. #13

    Thread Starter
    Junior Member
    Join Date
    Jan 2005
    Location
    Georgia
    Posts
    18

    Re: Count Down Help..

    lol this makes it like am/pm i want like a Count down say like 60 mins, 01:00:00, 00:59:59, 00:59:58 etc etc, but thanks this is interesting, ill try to tweak it, see what I can do with it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width