Collections and problems


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


Return Me.alertDesc

End Get

Set(ByVal value As String)

Me.alertDesc = value

End Set

End Property

Public Property TimeOfAlert() As DateTime


Return Me.alertTime

End Get

Set(ByVal value As DateTime)

Me.alertTime = value

End Set

End Property

Public Property IsAlertActive() As Boolean


Return Me.isAlertOn

End Get

Set(ByVal value As Boolean)

Me.isAlertOn = value

End Set

End Property


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


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()


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()))


End If

End While



End Sub

End Class



  • seancampbellseancampbell Pennsylvania, USA
    In the button click, you appear to have an End If that doesn't belong (right before your End While). Other then that, and the fact that you close your connection and reopen it. Other then that, maybe it is your Alert code? I have never done an Alert, I tend to stick with MsgBox or a custom MsgBox object I made.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


In this Discussion