Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…
Suggested Courses

715 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