Shouldn't this timer go off? 
Author Message
 Shouldn't this timer go off?

See the folowing code fragment

Private Sub timCLock_Timer()
Dim dteAlarm As Date
Dim dteCurrent As Date
dteCurrent = Now
'Enter Alarm Time Here
dteAlarm = "19:57:00 "

        Label3 = Hour(dteCurrent) & " :" & Minute(dteCurrent) & " :" &
Second(dteCurrent)

        Label4 = Hour(dteAlarm) & " :" & Minute(dteAlarm) & " :" &
Second(dteAlarm)

    If dteCurrent > dteAlarm Then
        Beep
    End If

End Sub

In my opinion the program should beep as soon as the current time is greater
then the alarm time.  Perhaps I am coparing the times incorrectly?

Thanks in advance



Sat, 21 Aug 1999 03:00:00 GMT  
 Shouldn't this timer go off?


12:59:11 GMT):

Change this line:

Quote:
>dteCurrent = Now

to:

dteCurrent = Format$(Now, "hh:mm:ss")

That'll make it work.

The reason is easy: Your way of assigning "Now" to
dteCurrent included the date while your dteAlarm only
consisted of the time. I'd even prefer to do it just the
other way around: Include the date in dteAlarm and keep
dteCurrent as it was, but that's a question of what you
want.

Best wishes

Mathias Schiffer, Germany



Sat, 21 Aug 1999 03:00:00 GMT  
 Shouldn't this timer go off?

[snip code fragments]

I don't much about the DATE variable (actually this is the first time I've
seen it) but whenever I did comparisions or subtractions of times I just
broke the times down into seconds (1 minute = 60, 1 hour= 60 * 60) that
would probably take care of your comparision problems. Who says what the
user sees has to be what is actually going on in the background.

also, doesn't this need to run every second to update the current time?

I don't think that I helped much but....

Farmguy
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
    Don't ask me nothing about nothing, I just might tell you the truth.
                                                        -B. Dylan
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=



Sat, 21 Aug 1999 03:00:00 GMT  
 Shouldn't this timer go off?


1997 21:22:19 GMT):

Quote:
>I don't much about the DATE variable (actually this is the first time I've
>seen it) but whenever I did comparisions or subtractions of times I just
>broke the times down into seconds (1 minute = 60, 1 hour= 60 * 60) that
>would probably take care of your comparision problems. Who says what the
>user sees has to be what is actually going on in the background.

The date-type is new in VB4. This code wouldn't work for
VB3. There, you'd probably use a Variant or simply strings
for that. In this special case, a string*8 would have been
enough, for example. Your solution would of course also
work, although it produces slightly more work for the
program.

Quote:
>also, doesn't this need to run every second to update the current time?

You're right. This code would be placed in a timer-routine,
using a timer-interval that is good enough (wouldn't have to
be 1000 msec or less neccessarily if it woulnd't need an
_exact_ alarm (watch the ">" that was used which makes it
neccessary to stop the alarm after a set time when once
having been started). Take a look at VB, the timer-routine
can easily be placed with the "clock"-icon in the toolbar.

Quote:
>I don't think that I helped much but....

We see you wanted to help. You had a nice idea and told it
to solve someone else's problem. That's about everything
this group is about. No need to worry if you're not an
expert in the field.

Mathias Schiffer, Germany



Sun, 22 Aug 1999 03:00:00 GMT  
 Shouldn't this timer go off?

dteCurrent includes the date.  This may be causing your problem.  Also,
note that this code will never Beep if your alarm time is 11:59 PM.

--
Keith Benedict
Software Engineer
Triad Systems

** The reply address is a no spam address. To send to me



Quote:
> See the folowing code fragment

> Private Sub timCLock_Timer()
> Dim dteAlarm As Date
> Dim dteCurrent As Date
> dteCurrent = Now
> 'Enter Alarm Time Here
> dteAlarm = "19:57:00 "

>         Label3 = Hour(dteCurrent) & " :" & Minute(dteCurrent) & " :" &
> Second(dteCurrent)

>         Label4 = Hour(dteAlarm) & " :" & Minute(dteAlarm) & " :" &
> Second(dteAlarm)

>     If dteCurrent > dteAlarm Then
>         Beep
>     End If

> End Sub

> In my opinion the program should beep as soon as the current time is
greater
> then the alarm time.  Perhaps I am coparing the times incorrectly?

> Thanks in advance



Sun, 22 Aug 1999 03:00:00 GMT  
 Shouldn't this timer go off?

Looks to me like dteAlarm only contains a time whereas dteCurrent
contains a fully qualified date.



Quote:
>See the folowing code fragment

>Private Sub timCLock_Timer()
>Dim dteAlarm As Date
>Dim dteCurrent As Date
>dteCurrent = Now
>'Enter Alarm Time Here
>dteAlarm = "19:57:00 "

>        Label3 = Hour(dteCurrent) & " :" & Minute(dteCurrent) & " :" &
>Second(dteCurrent)

>        Label4 = Hour(dteAlarm) & " :" & Minute(dteAlarm) & " :" &
>Second(dteAlarm)

>    If dteCurrent > dteAlarm Then
>        Beep
>    End If

>End Sub

>In my opinion the program should beep as soon as the current time is greater
>then the alarm time.  Perhaps I am coparing the times incorrectly?

>Thanks in advance

Geoff Stirling
Montreal, PQ, Canada

NOTE: Remove the trailing '*' in the REPLY-TO when replying by email



Tue, 24 Aug 1999 03:00:00 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. LostFocus doesn't go off when option button gets focus

2. This shouldn't work, but ...

3. It just shouldn't be this complicated...

4. Shouldn't this be easy?

5. Forms taking focus when they shouldn't

6. Please Help: Shouldn't this work?

7. Record Locking Shouldn't Be So Hard

8. EZTouchPOS Why you shouldn't buy it

9. It shouldn't have done that...

10. Textbox beeps and it shouldn't

11. VarType 8192 shouldn't be returned

12. MTS commited data when it shouldn't

 

 
Powered by phpBB® Forum Software