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
Printable View
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
use the datediff() function using hours, and then a timer to check if that number of hours has passed.
Try this function. Just replace the MsgBox with whatever you want to do to display the output, ie. Label1.Text = sOut
VB Code:
Private Function ToBDay(dOfBirth As Date) As Boolean Dim dNextBDay As Date Dim dRemaining As Date Dim sDays As String Dim sHours As String Dim sMinutes As String Dim sSeconds As String Dim sOut As String 'Figure out when the next birthday is iAge = CInt(DateDiff("d", CDate(0), Now - dOfBirth) \ 365.25) dNextBDay = DateAdd("yyyy", iAge + 1, dOfBirth) Do Until Now > dNextBDay dRemaining = dNextBDay - Now sDays = DateDiff("d", CDate(0), dRemaining) sHours = CStr(DateDiff("h", CDate(0), dRemaining) Mod 24) sMinutes = CStr(DateDiff("n", CDate(0), dRemaining) Mod 60) sSeconds = CStr(DateDiff("s", CDate(0), dRemaining) Mod 60) sOut = sDays & " Days, " & sHours & " Hours, " & sMinutes & " Minutes, " _ & sSeconds & " Seconds." If MsgBox(sOut, vbOKCancel) = vbCancel Then bExit = True Exit Do End If DoEvents Loop 'Should always evaluate true if the loop exits normally and 'DoEvents doesn't take a day. If Format(Now, "Short Date") = Format(nextbday, "Short Date") Then MsgBox ("Happy Birthday!") End If End Function Private Sub Test() ToBDay (CDate("7/20/1972")) End Sub
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 ?
Take this out of the loop and replace it with whatever you want to assign the string too.
VB Code:
If MsgBox(sOut, vbOKCancel) = vbCancel Then bExit = True Exit Do 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:
If bExit = True Then Exit Do 'it Rhymes :P Label1.Text = sOut
Whoops, I misread your last post. Try this in your button sub:
VB Code:
Dim sBDay As String sBDay = InputBox("Enter your birthdate", "Birthday") If IsDate(sBDay) Then ToBDay (CDate(sBDay)) Else MsgBox ("Not a valid date") End If
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.
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..?