PDA

View Full Version : An Alarm! (:



Fwd Motion
02-24-2012, 06:57 AM
Wrote this just messing around and I ended up using it! Just thought I'd share, haha

program Alarm; // By Fwd Motion

const
{*****************EDIT PREFERENCES HERE**************}

AlarmHour = '09'; //Hour to sound alarm! If it is a single digit, add a 0!
AlarmMinute = '45'; //Minute to sound alarm! If it is a single digit, add a 0!
AMorPM = 'AM'; //AM or PM?
AlarmPath = 'C:/Simba/Scripts/alarmclock.wav'; //Alarm Path

{**********************END SETUP*********************}

function TheTime: string;
var
Hour, Mins, Sec, MSec: Word;
PAM: string;
begin
DecodeTime(Now, Hour, Mins, Sec, MSec);
PAM := 'AM';
if (Hour > 12) then
begin
Hour := Hour - 12;
PAM := 'PM';
end else if (Hour = 12) then
PAM := 'PM'
else if (Hour = 0) then
Hour := 12;
Result := (Padz(IntToStr(Hour), 2) + ':' + Padz(IntToStr(Mins), 2) + ':' + Padz(IntToStr(Sec), 2) + ' ' + PAM);
end;

procedure SOUNDTHEALARM;
begin
repeat
sleep(500);
until TheTime >= (AlarmHour + ':' + AlarmMinute + ':00 ' + AMorPM);
if TheTime >= (AlarmHour + ':' + AlarmMinute + ':00 ' + AMorPM) then
begin
repeat
PlaySound(AlarmPath);
writeln('WakeUp!!!');
sleep(3000);
StopSound;
until (TheTime > (inttostr(strtoint(AlarmHour)+1)) + ':' + AlarmMinute + ':00 ' + AMorPM);
end;
end;

begin
SOUNDTHEALARM;
end.

P1nky
02-24-2012, 07:47 AM
Neat :), I remember when i was beginning to learn how to script, I attempted to make a alarm but horribly failed :(

Good Job.

Mushini
02-24-2012, 07:58 AM
Alarm is useful!

Fwd Motion
02-24-2012, 08:02 AM
I made this in a matter of like 10 minutes :P

By making this script, I learned that pascal, for some reason, uses a bunch of seemingly random numbers for the time, so the time almost literally needs to be decoded

I also learned that you can do (inttostr(strtoint('string')+1); Which is pretty cool :P

RyGuy
02-24-2012, 03:16 PM
Cool utility, but I think I'm gonna stick to my phone for now :P