Link to home
Create AccountLog in
Avatar of Perkentha1

asked on

Need a Time Comparison script written in VB

This is not urgent as it is merely for humor.

     We have a co-worker that strolls in darn near when he wants.  I would like a script that will check the system time against a set time (say 7:00 AM) and if the script is executed at 7:02 AM it reports displays back "the time is 7:02 AM you are 2 minutes late" and if the script is executed at 6:58 AM it says "Congradulations!  You are 2 minutes early!"  (Times are variables of course)

if possible the display back msg should not be to small, nor to large.  It is just for fun and conversation here in the office.

Thank you!
Avatar of sr75
Flag of United States of America image

Link to home
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of Perkentha1


Answer was just what I needed.

I modified it slightly, instead of an echo I add a call msgbox.  Code below.

strTime = "7:00 AM"
TimeDiff = DateDiff("n", strTime, time())
If TimeDiff > 0 then
      call msgbox ("You are " & TimeDiff & " minutes late!!!")

End If
If TimeDiff < 0 then
      TimeDiff = right(TimeDiff, len(TimeDiff) -1)
      call msgbox ("Congradulations!!!!" & vbcrlf & vbcrlf & _
                  "You are " & TimeDiff & " minutes early!!!")
End If