'To use:

' Use the horizontal scrolls to set date and time.
' Click "Set" button to set the alarm.
' Use the File menu to select a .wav file to play
'   when the alarm goes off.  Otherwise, the
'   default beep gets played.

'Declaration in declarations section of Form code:
Declare Function sndPlaySound Lib "MMSYSTEM" (ByVal lpszSoundName As String, ByVal uFlags As Integer) As Integer

Const SND_SYNC = &H0                 '  play synchronously (default)

Dim StartNow As Variant
Dim AlarmTime As String
Dim SetTime As String
Dim AlarmWentOff As Integer
Dim AlarmSet As Integer


' The rest of the code is for the controls on the form:
Sub Command1_Click ()
    AlarmTime = Text2.Text + " " + SetTime
    Text4.Text = "Alarm set: " + Text2.Text + " " + Text3.Text
    AlarmSet = True
End Sub

Sub Command2_Click ()
    End
End Sub

Sub ExitCtl_Click ()
    End
End Sub

Sub Form_Load ()
    StartNow = Now
    Text2.Text = Format(StartNow, "ddddd")
    SetTime = Format(StartNow, "ttttt")
    Temp = Left$(SetTime, 5)
    If Right$(Temp, 1) = ":" Then
	Temp = Left$(SetTime, 4)
    End If
    Text3.Text = Temp + Right$(SetTime, 3)
    AlarmWentOff = 0
    AlarmSet = False
End Sub

Sub HScroll1_Change ()
    NewNow = DateAdd("d", HScroll1.Value, Now)
    Text2.Text = Format(NewNow, "ddddd")
End Sub

Sub HScroll2_Change ()
    NewNow = DateAdd("n", HScroll2.Value, StartNow)
    SetTime = Format(NewNow, "ttttt")
    Temp = Left$(SetTime, 5)
    If Right$(Temp, 1) = ":" Then
	Temp = Left$(SetTime, 4)
    End If
    Text3.Text = Temp + Right$(SetTime, 3)
    'Text3.Text = Format(NewNow, "ttttt")
End Sub

Sub Timer1_Timer ()
    If AlarmSet Then
	If AlarmWentOff = 1 Then
	    Form1.Caption = "- " + Format(Now, "ttttt")
	Else
	    Form1.Caption = "* " + Format(Now, "ttttt")
	End If
    Else
	Form1.Caption = Format(Now, "ttttt")
    End If
    'Check to see if alarm goes off.
    If Len(AlarmTime) > 0 Then
	TimeDif = DateDiff("n", Now, AlarmTime)
	If TimeDif <= 0 And AlarmWentOff = 0 Then
	    AlarmWentOff = 1
	    If Text1.Text = "<default beep>" Then
		x = sndPlaySound("ding.wav", SND_SYNC)
	    Else
		' Play sound file; sound beep if none.
		x = sndPlaySound(CMDialog1.Filename, SND_SYNC)
	    End If
	End If
    End If
End Sub

Sub WaveCtl_Click ()
    CMDialog1.Action = 1

    Text1.Text = CMDialog1.Filename
End Sub

