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 ?Time.jpg
isnoend2001Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
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.

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

I'm working the time difference.
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

Martin LissOlder than dirtCommented:
Dim dteTaskTime As Date
Dim dteTaskTimeTom 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"

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

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

Start your 7-day free trial
isnoend2001Author 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
Martin LissOlder 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.

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
isnoend2001Author Commented:
Probably won't be PM she takes meds in the am
Martin LissOlder than dirtCommented:
Well the 9:00 is 9AM in both 12hr and 24hr formats so you should be OK.
isnoend2001Author Commented:
she also takes med before bed
Martin LissOlder 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.
isnoend2001Author Commented:
She said she takes meds twice a day in the am morning & pm before bed. i will post another question
isnoend2001Author Commented:
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
Martin LissOlder 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.
isnoend2001Author Commented:
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 ?
isnoend2001Author Commented:
Found it, sorry about the has-sell
had this
dteTaskTime = TimeValue("9:00") ' assumes military time
sb
dteTaskTime = TimeValue(dteTaskTime) ' assumes military time
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.