Results 1 to 8 of 8

Thread: Bday count down

  1. #1

    Thread Starter
    Lively Member Neo-dark's Avatar
    Join Date
    Oct 2004
    Location
    The neather world
    Posts
    114

    Bday count down

    Is there a way to create a birthdate count down..?
    what i exactly mean is that it counts the hours till a date a person put in into a input box...
    example:

    person enters date: 20 jan
    clock starts counting down till 20 jan: Day,hours,minutes
    i got kicked out of barnes and noble once for moving all the bibles into the fiction section"--FD

    Of course I'm a real doctor! I'll draw up my own diploma some time to prove it!-Dr Dis

  2. #2
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Bday count down

    use the datediff() function using hours, and then a timer to check if that number of hours has passed.

  3. #3
    Fanatic Member Comintern's Avatar
    Join Date
    Nov 2004
    Location
    Lincoln, NE
    Posts
    826

    Re: Bday count down

    Try this function. Just replace the MsgBox with whatever you want to do to display the output, ie. Label1.Text = sOut

    VB Code:
    1. Private Function ToBDay(dOfBirth As Date) As Boolean
    2.  
    3. Dim dNextBDay As Date
    4. Dim dRemaining As Date
    5. Dim sDays As String
    6. Dim sHours As String
    7. Dim sMinutes As String
    8. Dim sSeconds As String
    9. Dim sOut As String
    10.  
    11. 'Figure out when the next birthday is
    12. iAge = CInt(DateDiff("d", CDate(0), Now - dOfBirth) \ 365.25)
    13. dNextBDay = DateAdd("yyyy", iAge + 1, dOfBirth)
    14.  
    15. Do Until Now > dNextBDay
    16.     dRemaining = dNextBDay - Now
    17.     sDays = DateDiff("d", CDate(0), dRemaining)
    18.     sHours = CStr(DateDiff("h", CDate(0), dRemaining) Mod 24)
    19.     sMinutes = CStr(DateDiff("n", CDate(0), dRemaining) Mod 60)
    20.     sSeconds = CStr(DateDiff("s", CDate(0), dRemaining) Mod 60)
    21.     sOut = sDays & " Days, " & sHours & " Hours, " & sMinutes & " Minutes, " _
    22.            & sSeconds & " Seconds."
    23.     If MsgBox(sOut, vbOKCancel) = vbCancel Then
    24.         bExit = True
    25.         Exit Do
    26.     End If
    27.     DoEvents
    28. Loop
    29.  
    30. 'Should always evaluate true if the loop exits normally and
    31. 'DoEvents doesn't take a day.
    32. If Format(Now, "Short Date") = Format(nextbday, "Short Date") Then
    33.     MsgBox ("Happy Birthday!")
    34. End If
    35.  
    36. End Function
    37.  
    38.  
    39. Private Sub Test()
    40.  
    41. ToBDay (CDate("7/20/1972"))
    42.  
    43. End Sub
    Last edited by Comintern; Jan 6th, 2005 at 02:55 PM. Reason: Remove setting of value explicitly

  4. #4

    Thread Starter
    Lively Member Neo-dark's Avatar
    Join Date
    Oct 2004
    Location
    The neather world
    Posts
    114

    Re: Bday count down

    Works like a charm,cept i dont exactly know how to get the Bday date i made a button instead of your 'test'part,but is there a way to get it out of a input box ?
    i got kicked out of barnes and noble once for moving all the bibles into the fiction section"--FD

    Of course I'm a real doctor! I'll draw up my own diploma some time to prove it!-Dr Dis

  5. #5
    Fanatic Member Comintern's Avatar
    Join Date
    Nov 2004
    Location
    Lincoln, NE
    Posts
    826

    Re: Bday count down

    Take this out of the loop and replace it with whatever you want to assign the string too.

    VB Code:
    1. If MsgBox(sOut, vbOKCancel) = vbCancel Then
    2.         bExit = True
    3.         Exit Do
    4.     End If


    IE, put a label control on your form, and set it's Text property like this (where Label1 is the name of your label). The MsgBox was to let you exit the loop in the example. Make bExit a global variable, and have your cancel button set it to True.

    VB Code:
    1. If bExit = True Then Exit Do        'it Rhymes :P
    2. Label1.Text = sOut

  6. #6
    Fanatic Member Comintern's Avatar
    Join Date
    Nov 2004
    Location
    Lincoln, NE
    Posts
    826

    Re: Bday count down

    Whoops, I misread your last post. Try this in your button sub:

    VB Code:
    1. Dim sBDay As String
    2.  
    3. sBDay = InputBox("Enter your birthdate", "Birthday")
    4. If IsDate(sBDay) Then
    5.     ToBDay (CDate(sBDay))
    6. Else
    7.     MsgBox ("Not a valid date")
    8. End If

  7. #7
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: Bday count down

    Put a SLEEP statement into that loop, otherwise it's going to iterate at the microsecond level and it only needs to go every second or so.

  8. #8

    Thread Starter
    Lively Member Neo-dark's Avatar
    Join Date
    Oct 2004
    Location
    The neather world
    Posts
    114

    Re: Bday count down

    Okay,works like a charm..thank you so much ^_^^

    hmm..sleep..?:S okay ill try to look it up myself but if i cant find it..please explain..?
    i got kicked out of barnes and noble once for moving all the bibles into the fiction section"--FD

    Of course I'm a real doctor! I'll draw up my own diploma some time to prove it!-Dr Dis

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