isnoend2001
asked on
Complicated time calculation vb6
I have a mshflexdrid that has a time due and another column
that calculates how many hours until the next reminder is due
by ncomparing the pc time to the next hour if past the current hour then
it would be the next days hours
also have a refresh button to update the hours
the cells in the grid:
gridMaster (name of grid)
Const mgrdTaskTime = 3 reminder due time
Const mgrdDueDate = 5 next due time in hours if more than one
how can this be calculated ?
that calculates how many hours until the next reminder is due
by ncomparing the pc time to the next hour if past the current hour then
it would be the next days hours
also have a refresh button to update the hours
the cells in the grid:
gridMaster (name of grid)
Const mgrdTaskTime = 3 reminder due time
Const mgrdDueDate = 5 next due time in hours if more than one
how can this be calculated ?
First a suggestion. I might not understand the purpose of the Refresh button but why not use a timer instead?
ASKER
timer would probably work better, if not my sister could click the refresh button to update the time
If the timer ran every minute (or less) why would she need the button at all?
I'm working the time difference.
I'm working the time difference.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks Marty
If the timer ran every minute (or less) why would she need the button at all?
might be confusing if values change, have to give more thought
the code you gave needs 24 hour time
if i remember right then converting 12hr to 24hr is more difficult than 24 to 12 hr
Have to look i may have code to convert it.
Talking to my sister this AM she really has a difficult time taking her medicine
She stare at it for a while, i told her my solution , sound
drum roll then applause
If the timer ran every minute (or less) why would she need the button at all?
might be confusing if values change, have to give more thought
the code you gave needs 24 hour time
if i remember right then converting 12hr to 24hr is more difficult than 24 to 12 hr
Have to look i may have code to convert it.
Talking to my sister this AM she really has a difficult time taking her medicine
She stare at it for a while, i told her my solution , sound
drum roll then applause
If you know that the task time is a PM time then add this line between lines 10 and 12 with some appropriate If/End If statement surrounding it.
dteTaskTime = DateAdd("h", 12, dteTaskTime)
In any case one again you're welcome and I'm glad I was able to help.
In my profile you'll find links to some articles I've written that may interest you
including these two new ones.
Creating your own Excel Formulas and doing the impossible
A Guide to Writing Understandable and Maintainable VBA Code
Marty - MVP 2009 to 2015, Experts-Exchange Top Expert Visual Basic Classic 2012 to 2014
dteTaskTime = DateAdd("h", 12, dteTaskTime)
In any case one again you're welcome and I'm glad I was able to help.
In my profile you'll find links to some articles I've written that may interest you
including these two new ones.
Creating your own Excel Formulas and doing the impossible
A Guide to Writing Understandable and Maintainable VBA Code
Marty - MVP 2009 to 2015, Experts-Exchange Top Expert Visual Basic Classic 2012 to 2014
ASKER
Probably won't be PM she takes meds in the am
Well the 9:00 is 9AM in both 12hr and 24hr formats so you should be OK.
ASKER
she also takes med before bed
OK if you need any help please start a new question but your "Probably won't be PM she takes meds in the am" and "she also takes med before bed" statements seem contradictory.
ASKER
She said she takes meds twice a day in the am morning & pm before bed. i will post another question
ASKER
sent at 5:39 Pm
DetermineNextTask ("9:00 PM")
returns Task due in 15 hours and 20 minutes
should return 3 hours 25 minutes
Sub DetermineNextTask(dteTaskT ime As Date)
Dim dteTimeNow As Date
Dim lngDifference As Long
Dim lngHours As Long
Dim lngMinutes As Long
dteTimeNow = TimeValue(Now)
' This is set up for a 9AM task
dteTaskTime = TimeValue("9:00") ' assumes military time
If dteTimeNow > dteTaskTime Then
' Format a date+time value that represents the task time tomorrow
dteTaskTimeTom = Format(Now + 1, "short date") & " " & dteTaskTime
lngDifference = Abs(DateDiff("s", dteTaskTimeTom, Now))
Else
lngDifference = DateDiff("s", dteTimeNow, dteTaskTime)
lngHours = (lngDifference \ 60) \ 60
lngMinutes = (lngDifference - (lngHours * 60 * 60)) \ 60
End If
lngHours = (lngDifference \ 60) \ 60
lngMinutes = (lngDifference - (lngHours * 60 * 60)) \ 60
MsgBox "Task due in " & lngHours & " Hours and " & lngMinutes & " Minutes"
End Sub
DetermineNextTask ("9:00 PM")
returns Task due in 15 hours and 20 minutes
should return 3 hours 25 minutes
Sub DetermineNextTask(dteTaskT
Dim dteTimeNow As Date
Dim lngDifference As Long
Dim lngHours As Long
Dim lngMinutes As Long
dteTimeNow = TimeValue(Now)
' This is set up for a 9AM task
dteTaskTime = TimeValue("9:00") ' assumes military time
If dteTimeNow > dteTaskTime Then
' Format a date+time value that represents the task time tomorrow
dteTaskTimeTom = Format(Now + 1, "short date") & " " & dteTaskTime
lngDifference = Abs(DateDiff("s", dteTaskTimeTom, Now))
Else
lngDifference = DateDiff("s", dteTimeNow, dteTaskTime)
lngHours = (lngDifference \ 60) \ 60
lngMinutes = (lngDifference - (lngHours * 60 * 60)) \ 60
End If
lngHours = (lngDifference \ 60) \ 60
lngMinutes = (lngDifference - (lngHours * 60 * 60)) \ 60
MsgBox "Task due in " & lngHours & " Hours and " & lngMinutes & " Minutes"
End Sub
I ran your code, as is, at 5:57 PM and was told the next task was due in 3 hrs and 3 minutes.
ASKER
I don't understand
ran at 6:04 my pc time
DetermineNextTask ("9:00 PM")
returns 14 hrs 55 minutes what could be the difference ?
ran at 6:04 my pc time
DetermineNextTask ("9:00 PM")
returns 14 hrs 55 minutes what could be the difference ?
ASKER
Found it, sorry about the has-sell
had this
dteTaskTime = TimeValue("9:00") ' assumes military time
sb
dteTaskTime = TimeValue(dteTaskTime) ' assumes military time
had this
dteTaskTime = TimeValue("9:00") ' assumes military time
sb
dteTaskTime = TimeValue(dteTaskTime) ' assumes military time