Re: Problems with count down
this is simple method
vb Code:
HourCount = Thour - Hour(Now)
If Hour(Now) > Thour Then hourcount = 24 + hourcount
Re: Problems with count down
[Update on code]
this is what i have so far after shortening it a little
Code:
Do Until InfoCount = Intcount
For prum = 0 To Intcount - 1
InfoCount = InfoCount + 1
If InfoCount = Intcount Then
For d = Intcount To 15
Picture4(d).Visible = False
Next
End If
Thour = .Fields("TimeHourDue").Value 'Due Hour
Tminute = .Fields("TimeMinuteDue").Value 'Due Minute
HourCount = 0
MinuteCount = 0
MinuteCount = Tminute - Minute(Now)
If Minute(Now) > Tminute Then
MinuteCount = MinuteCount + 60
HourCount = HourCount + 1
End If
HourCount = Thour - Hour(Now)
If Hour(Now) > Thour Then
HourCount = HourCount + 24
End If
Next
TDue = HourCount & " Hours and " & MinuteCount & " Minutes."
Label3(prum).Caption = TDue
Still it comes up with a negative value. Can't seem to detect the hour(now) is greater than the due hour. Perhaps in my for next... loop?
Re: Problems with count down
You should use the DateDiff function to compare times.
Re: Problems with count down
i found a tutorial on the DateDiff function, but!! can you show me how to assimilate the data from my database into the function, to compare with the time now?
Print DateDiff("h", #1/1/2001#, Now)
*wouldn't be something like
Print DateDiff("h", THour, Now)
^^'
Re: Problems with count down
I'm not sure what you mean, because your post contains the answer.
The only potential problem is that Print may not be the output you want.
Re: Problems with count down
i don't think datediff is what i'm after. Thour is an hour value i.e. 20 = 8pm as such. Am being returned a value of somethings around 960046 (as shown in msgbox showing datediff value). what have i missed? :eek2:
Re: Problems with count down
Ah, I see the problem - THour (and your database field) do not contain a time at all, just a number which represents the hour of the time. Due to the way VB stores dates, it treats that number as midnight on a particular day (early 1900 I think).
In that case you should use the TimeSerial function to create a time based on that number - and compare it to just Time instead of Now.
Re: Problems with count down
you should combine the hours and minutes, then calculate the time difference in minutes, then recalc back to hours and minutes to display
i still didn't figure why you are using a loop for this, i must have missed something, it appears to only use results from last iteration of loop