Alarm Clock
- Here is my Alarm Clock, http://smallbasic.com/program/?GQR102. Can someone look at it and see if there is any improvements to be made?
All Replies
- Nice work.
I know you hide the window during countdown, but here is an idea for a countdown phase before the alarm goes off. When this While loop is completed the alarm is ready to go off. The While loop ends when (hour1 <> Clock.Hour Or minutes1 <> Clock.Minute) is FALSE. This only happens when (hour1 = Clock.Hour And minutes1 = Clock.Minute) so no further checking of the time is required - just start the alarm.
Also it would be good after the alarm has gone off to try not to virtually repeat the Snooze code twice, perhaps a Subroutine could help here. If you can manage to use Subroutines rather than lots of GoTo's this generally makes for easier code to follow, but sometimes the odd GoTo is very useful.
'Do a countdown while waiting
While (hour1 <> Clock.Hour Or minutes1 <> Clock.Minute)
'Sound.PlayClick()
hourRemain = hour1-Clock.Hour 'Hours remaining
minRemain = minutes1-Clock.Minute ' Minutes remaining
secRemain = 0-Clock.Second ' Seconds remaining
If (secRemain < 0) Then 'If we have less than 0 seconds left, then take it off the minute (THIS IS MOSTLY TRUE)
secRemain = secRemain+60
minRemain = minRemain-1
EndIf
If (minRemain < 0) Then 'If we have less tha 0 minutes left, then take it off the hour
minRemain = minRemain+60
hourRemain = hourRemain-1
EndIf
If (hourRemain < 0) Then 'If we have less than 0 hours left then take it off the day
hourRemain = hourRemain+24
EndIf
TextWindow.CursorLeft = 0
TextWindow.CursorTop = 0
TextWindow.WriteLine(hourRemain+" hours "+minRemain+" minutes "+secRemain+" seconds left ")
Program.Delay(1000)
EndWhile


