SYnc On: Sync Rate 0
 
Global Alarm$
Alarm$ = "00:00:00"
Dim Time(3) As Integer
 
Do
	`Set an alarm if user presses the "s" key.
	If Scancode() = 31 Then Set_alarm()
 
	Time$ = Get Time$()
 
	cls
	Text 0,0,Time$
	Text 0,20,Alarm$
	Text 130,0,"Press <s> to set an alarm."
 
	If Time$ = Alarm$ Then Ring_Alarm()	
	Sync	
loop
 
 
Function Set_Alarm()
 
Sync Rate 10
Stage = 1
 
Do
	cls
	Text 0,0,Get Time$()
	Text 0,20,"Alarm: " + Alarm$
	Text 0,40,"Stage: " + Str$(Stage)
	Text 130,0,"Press up and down to change the time value."
	Text 130,20,"Press left and right to change which value you are editing."
	Text 130,40,"And press enter to save alarm."
 
 
	If Upkey() = 1 Then Time(Stage) = Time(Stage) + 1
	If Downkey() = 1 Then Time(Stage) = Time(Stage) - 1
	If Rightkey() = 1 Then Stage = Stage + 1
	If Leftkey() = 1 Then Stage = Stage - 1
	If Returnkey() = 1 Then Exit
 
	temp = Time(1)
	Hours$ = str$(temp)
	If Time(1) < 10 Then Hours$ = "0" + Hours$
 
	temp = Time(2)
	Minutes$ = str$(temp)
	If Time(2) < 10 Then Minutes$ = "0" + Minutes$
 
	Temp = Time(3)
	Seconds$ = str$(Temp)
	If Time(3) < 10 Then Seconds$ = "0" + Seconds$
 
	Alarm$ = Hours$ + ":" + Minutes$ + ":" + Seconds$
 
	Sync
loop
 
Sync Rate 0
 
Endfunction 
 
Function Ring_Alarm()
 
	Text 0,50,"RRRRRRRRIIIIIIIIINNNNNNNNNGGGGGGGGGGGG!!!!!!!!!!!!"
	Text 130,0,"Press any key to continue."
	wait key
endfunction