|
-
Jan 6th, 2005, 01:40 PM
#1
Thread Starter
Lively Member
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
-
Jan 6th, 2005, 01:42 PM
#2
Re: Bday count down
use the datediff() function using hours, and then a timer to check if that number of hours has passed.
-
Jan 6th, 2005, 02:52 PM
#3
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:
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
Last edited by Comintern; Jan 6th, 2005 at 02:55 PM.
Reason: Remove setting of value explicitly
-
Jan 6th, 2005, 05:20 PM
#4
Thread Starter
Lively Member
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
-
Jan 6th, 2005, 05:37 PM
#5
Re: Bday count down
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
-
Jan 6th, 2005, 05:43 PM
#6
Re: Bday count down
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
-
Jan 6th, 2005, 07:29 PM
#7
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.
-
Jan 7th, 2005, 06:34 AM
#8
Thread Starter
Lively Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|