Hello,
Please I need serious help here in sorting the collection and VB code below. Basically, I would like to display reminders from the database to the screen via messageboxes when the user clicks Button1, as long as the time and date has been reached.
But when I click on Button1 (see code below), I am not getting any output whatsoever. Do anybody know why?
Code Snippet
Public Class Alert
Dim alertDesc As String = String.Empty
Dim alertTime As DateTime = DateTime.Now
Dim isAlertOn As Boolean = False
Dim timer As New System.Timers.Timer(1000) 'every second
Public Property AlertDescription() As String
Get
Return Me.alertDesc
End Get
Set(ByVal value As String)
Me.alertDesc = value
End Set
End Property
Public Property TimeOfAlert() As DateTime
Get
Return Me.alertTime
End Get
Set(ByVal value As DateTime)
Me.alertTime = value
End Set
End Property
Public Property IsAlertActive() As Boolean
Get
Return Me.isAlertOn
End Get
Set(ByVal value As Boolean)
Me.isAlertOn = value
End Set
End Property
'Constructor
Public Sub New(ByVal descOfAlert As String, ByVal timeOfAlert As DateTime)
Me.alertDesc = descOfAlert
Me.alertTime = timeOfAlert
Me.isAlertOn = True
Me.timer.AutoReset = True
Me.timer.Enabled = True
AddHandler timer.Elapsed, AddressOf timer_elapsed
Me.timer.Start()
End Sub
Private Sub timer_elapsed(ByVal sender As Object, ByVal e As System.Timers.ElapsedEventArgs)
If Me.isAlertOn Then
If Me.alertTime = DateTime.Now Or Me.alertTime <= DateTime.Now.AddMinutes(-2) Then
System.Windows.Forms.MessageBox.Show("alert from " & Me.AlertDescription)
Me.isAlertOn = False
End If
End If
End Sub
End Class
Code Snippet
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If con.State = ConnectionState.Open Then con.Close()
con.Open()
cmd = New SqlCommand("SELECT REM_MEMO, REM_DATE FROM dbo.MY_CONTACTS Where REM_STATUS = 'True'", con)
Dim sdr As SqlDataReader = cmd.ExecuteReader
While sdr.HasRows = True
Dim newAlert As New Alert(Reminder_data_reader("REM_NOTE").ToString(), DateTime.Parse(Reminder_data_reader("REM_DATE").ToString()))
Me.collectionOfAlerts.Add(newAlert)
End If
End While
sdr.Close()
con.Close()
End Sub
End Class
Thanks
Comments
-firesickle.com