# 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 ?
###### Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Older than dirtCommented:
First a suggestion. I might not understand the purpose of the Refresh button but why not use a timer instead?
0
Author Commented:
timer would probably work better, if not my sister could click the refresh button to update the time
0
Older than dirtCommented:
If the timer ran every minute (or less) why would she need the button at all?

I'm working the time difference.
0
Older than dirtCommented:
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

' Format a date+time value that represents the task time tomorrow
dteTaskTimeTom = Format(Now + 1, "short date") & " " & dteTaskTime
Else
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"
0

Experts Exchange Solution brought to you by

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Author Commented:
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
0
Older than dirtCommented:
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.

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
0
Author Commented:
Probably won't be PM she takes meds in the am
0
Older than dirtCommented:
Well the 9:00 is 9AM in both 12hr and 24hr formats so you should be OK.
0
Author Commented:
she also takes med before bed
0
Older than dirtCommented:
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.
0
Author Commented:
She said she takes meds twice a day in the am morning & pm before bed. i will post another question
0
Author Commented:
sent at 5:39 Pm

returns Task due in 15 hours and 20 minutes
should return 3 hours 25 minutes

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

' Format a date+time value that represents the task time tomorrow
dteTaskTimeTom = Format(Now + 1, "short date") & " " & dteTaskTime
Else
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
0
Older than dirtCommented:
I ran your code, as is, at 5:57 PM and was told the next task was due in 3 hrs and 3 minutes.
0
Author Commented:
I don't understand
ran at 6:04 my pc time
returns 14 hrs 55 minutes what could be the difference ?
0
Author Commented:
Found it, sorry about the has-sell
dteTaskTime = TimeValue("9:00") ' assumes military time
sb