Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Setting an alarm 2

Status
Not open for further replies.

RonRepp

Technical User
Feb 25, 2005
1,031
US
Hi all:

I have a program that is supposed to run different procedures when an alarm goes off. Unfortunately, the alarm never goes off. I've made this work before, but for some reason, it isn't now.

[code>>frmScheduler]

Private Sub Timer1_Timer()
Static AlarmSounded As Integer
Dim Boo As Boolean
On Error Resume Next

If lblTime.Caption <> CStr(Time) Then
' It's now a different second than the one displayed.
If Second(Now) = 0 Then
Boo = GetNextScheduleTime(CStr(Time))
End If

'If Time = AlarmTime And Not AlarmSounded Then
If Boo And Not AlarmSounded Then
Beep
'Enter the run code here
MsgBox "This is where to put the code to run the email program", vbOKOnly, App.Title
'frmAdmin.StartProcess


AlarmSounded = True
ElseIf Time < AlarmTime Then
AlarmSounded = False
End If
If WindowState = conMinimized Then
' If minimized, then update the form's Caption every minute.
If Minute(CDate(Caption)) <> Minute(Time) Then SetCaptionTime
Else
' Otherwise, update the label Caption in the form every second.
lblTime.Caption = Time
End If
End If
End Sub
[/code]


[code>>Public module]

Public Function GetNextScheduleTime(ByVal strTime As String) As Boolean
Dim i As Integer
Dim Boo As Boolean
Dim itmX As ListItem
For i = 0 To frmScheduler.LV1.ListItems.Count - 1
Set itmX = frmScheduler.LV1.ListItems(i)
If Hour(CDate(itmX.SubItems(1))) = Hour(CDate(strTime)) Then
If Minute(CDate(itmX.SubItems(1))) = Minute(CDate(strTime)) Then
AlarmTime = CDate(itmX.SubItems(1))
Boo = True
Exit For
Else
Boo = False
Exit For
End If
Else
Boo = False
End If
Next
GetNextScheduleTime = Boo
End Function
[/code]


The timer works in the fact that it hits the function, but the function always returns false. In fact, it stops on the bolded line: Set itmX = frmScheduler.LV1.ListItems(i)

Any help will be greatly appreciated.




Ron Repp

If gray hair is a sign of wisdom, then I'm a genius.

My newest novel: Wooden Warriors
 
... probably something to do with the fact that a ListItems index is 1-based rather than 0-based ...
 
Sorry...Yes, you were correct. I didn't want to broadcast my stupidity.

Thanks,


Ron Repp

If gray hair is a sign of wisdom, then I'm a genius.

My newest novel: Wooden Warriors
 
<I didn't want to broadcast my stupidity.

Why not? I do it all the time. [lol]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top