Link to home
Start Free TrialLog in
Avatar of isnoend2001
isnoend2001Flag for United States of America

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 ?User generated image
Avatar of Martin Liss
Martin Liss
Flag of United States of America image

First a suggestion. I might not understand the purpose of the Refresh button but why not use a timer instead?
Avatar of isnoend2001

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.
ASKER CERTIFIED SOLUTION
Avatar of Martin Liss
Martin Liss
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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 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
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.
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.
She said she takes meds twice a day in the am morning & pm before bed. i will post another question
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(dteTaskTime 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
I ran your code, as is, at 5:57 PM and was told the next task was due in 3 hrs and 3 minutes.
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 ?
Found it, sorry about the has-sell
had this
dteTaskTime = TimeValue("9:00") ' assumes military time
sb
dteTaskTime = TimeValue(dteTaskTime) ' assumes military time