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

asked on

Compare 2 long times using vb6

this eub will be called every 10 seconds by a timer

Private Sub TimeCheck
dim TimeDifference as integer
dim TimeNow as ?
dim TaskTime as ?
TaskTime = 0500 '5AM
gintDailyReminder = 2 'from ini file(Hours)
TaskTime = TaskTime - megintDailyReminder

TimeDifference = timenow - gintDailyReminder
If TimeDifference > 2 then exit sub
Select Case TimeDifference
Case 2 
  MsgBox "You need to take your medicine in 2 hours at " & TaskTime 'convert to AM/PM
Case 1
  MsgBox "You need to take your medicine in 1 hour at " & TaskTime 'convert to AM/PM
Case Else
  MsgBox "You Forgot to take your medicine at " & TaskTime 'convert to AM/P
End Select

Open in new window

how can this be done ?
Avatar of Martin Liss
Martin Liss
Flag of United States of America image

They should probably be Date variables and you should look up and use DateDiff to determine the difference.
In other words here is some code. I place a breakpoint on line 6, ran the code, waited a few seconds and then let it run and the Msgbox told me "4".

Dim StartTime As Date
Dim EndTime As Date

StartTime = Now

EndTime = Now

MsgBox DateDiff("s", StartTime, EndTime)

Open in new window

Avatar of isnoend2001

ASKER

Thanks Mart, forget my email
I looked at this the datdsiff, but it looked like it worked with dates and not times
working with  long times has got me stumped
Have to run an errand be back in a couple hours
What do your "long times" look like.
1700 = 5Pm
0500 = 5AM
Is 1700 a part of the file name that contains the date?
No it only contains the time
fName = "Dy" & Format(DTPicker1.Value, "HHMM") & ".rtf"
 gives this: Dy1700.rtf
the Dy & .rtf are removed
Does this help?

Dim StartTime As Date
Dim EndTime As Date

' These two would not be in your program. They just represent
' the two values you start with.
Const STRING1 = "530"
Const STRING2 = "1700"

' Create a time value from the first character of the string if the string has 3
' characters, or the first two characters if it has 4, plus ":" plus the
' last two characters
StartTime = Left$(STRING1, Len(STRING1) - 2) & ":" & Right$(STRING1, 2)
EndTime = Left$(STRING2, Len(STRING2) - 2) & ":" & Right$(STRING2, 2)

' Subtract the two values and show the difference two ways
MsgBox "The difference is " & Format(EndTime - StartTime, "HH:MM")
MsgBox "or put another way " & Left$(Format(EndTime - StartTime, "HH:MM"), 2) & " Hours and " _
                             & Right$(Format(EndTime - StartTime, "HH:MM"), 2) & " Minutes"

Open in new window

did not realize this was so envolved
In looking at the code i do not see the comparison to the users system time.
Better explain more this is a reminder that happens every day at a certain time. and has the option
to set a reminder up to 2 hours before the reminder time
For example
Sister has set to take her medicine every morning at 9Am and has set a reminder of 2 hours
so at 7Am 2 hours before 9Am the message "you have to take your medicine in 2 hours"
then again at 8Am "you have to take your medicine in 1 hour" these  pre warnings are optional
Just realized that I cannot tell her to delete the file each day after she takes the medicine. i will have to
make something to flag the  task done
User generated image
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
What is megintDailyReminder? Did you mean gintDailyReminder?
'TaskTime = TaskTime - megintDailyReminder
 yes a typo
I will look into the google calendar. couple things that i have concerns about
Afew years ago i used google phone for long distance which was free and in my gmail, suddenly it was gone so i bought a tracphone.
need a internet connection, last week my sisters was down all day
Forgot
Thanks for all your help
You don't have to have an internet connection to use Google Mail (lookup Google Offline) and the alerts can be emails rather than or in addition to pop-ups.

How often does TimeCheck run?