Using System Time

Posted on 1999-06-29
Medium Priority
Last Modified: 2010-05-02
I created a clock application identical to the one in the MSDN help system example.
I also created a public variant variable called AlarmTime in the subroutine for the timer as seen below I have it check to see if the AlarmTime is less then Time or if it is not equal to 0. "0" is what the variable is set to if no alarm time is entered into a masked edit box on the form.
Play_Sound is a sub that calls a WIN32.API function for the alarm sound.

The whole thing works perfect as long as the AlarmTime variable is not above 09:59:59 AM, after that it plays as soon as you set the alarm, it would seem that it thinks 10:00:00 AM is < then 9:00:00 AM. I thought the system time was the number of seconds since midnight. How do I fix the sub below?

Private Sub Timer1_Timer()
If lblTime.Caption <> CStr(Time) Then
    lblTime.Caption = Time
    If AlarmTime < CStr(Time) And AlarmTime <> 0 Then
    End If
End If
End Sub
Question by:timothy1
  • 2
LVL 18

Accepted Solution

mdougan earned 200 total points
ID: 1520658
You should not be comparing the string version of the time values, you should convert the alarmtime to a date using the CDate function, then you should use Now() to get the current Date/Time, then you should do a DateDiff call to see if the current Date/Time is greater than the Alarm time.  This will also work if the Alarm time is 11:59 PM and the current time is 12 midnight (because you have the dates and the times)  Speakin of which, you should prompt your user to enter a date for the alarm or take the current date as a default.

if sDate is the alarm date and sTime is the alarm time:

        vTime = Format(Now(), "mm/dd/yyyy hh:nn:ss AM/PM")
        vDiff = DateDiff("s", vTime, sDate & " " & sTime)
        If (vDiff < 1) Then

LVL 18

Expert Comment

ID: 1520659
Actually, in the example I gave, I didn't convert the "alarm time" into a date using CDate, I just concatenated a string of date in the format of mm/dd/yyyy with a space and then with a string of time in the format of hh:nn:ss AM/PM.

Author Comment

ID: 1520660

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

587 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question