VB.NET - still trying to get this.. - Asked By jenn on 16-Dec-11 05:34 PM

Earn up to 20 extra points for answering this tough question.
hi guys-
i am still trying to get this right and am just not getting it LOL.
i have a listview with 3 columns- colDate:colTime:colName-

what i want to have happen is this:
i want to be able to set multiple reminder type alarms - allowing me to select a specific date from datetime picker and typing in my required time-

then  hold them in a listview.

when the date and the time = todays date and todays time- i want a dialog box to show (this is using the colName txt).

this is all of the coding i have on this so far- and as you can see, some of it is commented out- because those attempts did not work.

i had it working when i was just wanting it to go by the time. but what if i dont want to make my reminder for today? i want to make one for next month sometime- and thats when all hell broke loose LOLLLLL!

okay here is ALL the code i have so far.
Imports System.IO
Imports System.Xml
Imports System.Xml.XPath
  
Public Class frmReminder
  Private IsFileSaved As Boolean = False
  Public ReminderIsSaved As Boolean = True
  
  
#Region "Loads"
  Private Sub frmReminder_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    ReadReminderList()
    lblDateDisp.Text = Date.Now
    lblDispTime.Text = TimeOfDay
  End Sub
  
  Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    Me.lblDispTime.Text = TimeOfDay 'runs the timer label
  
   ''''''''' ''''''  '''For Each item As ListViewItem In Me.Listview1.Items
    ''''''''  '    If item.SubItems(0).Text = Me.lblDispTime.Text Then
   ''''''''   '      MsgBox(item.SubItems(1).Text)
    ''''''''  '    End If
   '''''''''   'Next
  
     ''''''''' ''For Each item As ListViewItem In Me.Listview1.Items
     '''''''' ''    If item.SubItems(0).Text = Me.lblDateDisp.Text AndAlso item.SubItems(1).Text = lblDispTime.Text Then
    ''''''''''      MsgBox(item.SubItems(2).Text)
     '''''''' ''    End If
   '''''''''''''   ''Next
  
    For Each item As ListViewItem In Me.ListView1.Items
      If item.SubItems(0).Text = Date.Now And item.SubItems(1).Text = TimeOfDay Then
        MsgBox(item.SubItems(2).Text)
      End If
    Next
  
  End Sub
  
  Private Sub ReadReminderList()
    If Not System.IO.File.Exists(Application.StartupPath & "\ReminderList.xml") Then Exit Sub
    Dim doc As New XmlDocument
    Try
      doc.Load(Application.StartupPath & "\ReminderList.xml")
      For Each node As XmlNode In doc.SelectNodes("//Item")
        Dim item As New ListViewItem
        Dim nodeAttributes As XmlAttributeCollection = node.Attributes
        item.Text = nodeAttributes(0).InnerText
        item.SubItems.Add(nodeAttributes(1).InnerText)
        item.SubItems.Add(nodeAttributes(2).InnerText)
        Listview1.Items.Add(item)
      Next
      doc = Nothing
    Catch ex As Exception
      Listview1.Items.Clear()
    End Try
  End Sub
#End Region
  
#Region "Events"
  Private Sub btnRemSel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRemSel.Click
    If Listview1.SelectedIndices.Count > 0 Then
      If MessageBox.Show("Are You Sure You Want To Delete This Reminder?", "Remove Reminder", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) = Windows.Forms.DialogResult.Yes Then
        For i As Integer = Listview1.SelectedIndices.Count - 1 To 0 Step -1
          Listview1.Items.RemoveAt(Listview1.SelectedIndices(i))
          ReminderIsSaved = False
        Next
      End If
    End If
    SaveReminderList()
  End Sub
  
  Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
    'Identify what we are wanting to add
    Dim myAlarmDate As String '0
    Dim myAlarmTime As String '1
    Dim myAlarmName As String '2
  
  
    'locating what we are adding
    myAlarmDate = dtpSelect.Text
    myAlarmTime = txtAlTime.Text
    myAlarmName = txtAlText.Text
  
  
    'adding the items into the listview
    Dim Lvitem As ListViewItem
    Lvitem = Me.Listview1.Items.Add(myAlarmDate)
    Lvitem.SubItems.Add(myAlarmTime)
    Lvitem.SubItems.Add(myAlarmName)
  
    'Clearing the textboxes for another entry
    dtpSelect.Text = Date.Now
    txtAlTime.Text = ""
    txtAlText.Text = ""
  
    If File.Exists(Application.StartupPath & "\ReminderList.xml") Then
      File.Delete(Application.StartupPath & "\ReminderList.xml")
    End If
    SaveReminderList()
  End Sub
#End Region
  
#Region "Closing"
  Private Sub frmReminder_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
    Dim Msg As String = "Are you sure you want to close the reminder?" & Environment.NewLine & Environment.NewLine
    Msg &= "If you close the reminder you will not be reminded" & Environment.NewLine
    Msg &= "Use Minimize to send Reminder to the task bar!"
    If MessageBox.Show(Msg, "Exiting", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = DialogResult.No Then
      e.Cancel = True
    End If
  End Sub
  Private Sub SaveReminderList()
    Dim writer As XmlTextWriter = New XmlTextWriter(Application.StartupPath & "\ReminderList.xml", System.Text.Encoding.Unicode)
    writer.Formatting = Formatting.Indented
    writer.Indentation = 4
    writer.WriteStartDocument()
    writer.WriteWhitespace(Environment.NewLine)
    writer.WriteStartElement("Reminder")
    writer.WriteWhitespace(Environment.NewLine)
    For i As Integer = 0 To Listview1.Items.Count - 1
      writer.WriteStartElement("Item")
      writer.WriteAttributeString("Date", Listview1.Items(i).SubItems(0).Text)
      writer.WriteAttributeString("Time", Listview1.Items(i).SubItems(1).Text)
      writer.WriteAttributeString("Name", Listview1.Items(i).SubItems(2).Text)
  
      writer.WriteEndElement()
      writer.WriteWhitespace(Environment.NewLine)
    Next
    writer.WriteEndElement()
    writer.WriteWhitespace(Environment.NewLine)
    writer.WriteEndDocument()
    writer.Close()
  End Sub
  
#End Region
  
#Region "Hide and Show"
  
  Private Sub frmReminder_SizeChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.SizeChanged
    If WindowState = FormWindowState.Minimized Then
      Me.Visible = False
    End If
  End Sub
  
  Private Sub Reminder_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Reminder.MouseClick
    If WindowState = FormWindowState.Normal Then
      Me.Visible = False
    End If
  End Sub
  
  Private Sub Reminder_MouseDoubleClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Reminder.MouseDoubleClick
    Me.Visible = True
    If WindowState = FormWindowState.Minimized Then
      Me.WindowState = FormWindowState.Normal
    End If
  End Sub
  
  
  Private Sub ShowToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ShowToolStripMenuItem.Click
    Me.Visible = True
    If WindowState = FormWindowState.Minimized Then
      Me.WindowState = FormWindowState.Normal
    End If
  End Sub
  
  Private Sub StopToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles StopToolStripMenuItem.Click
    Me.Visible = True
    If WindowState = FormWindowState.Minimized Then
      Me.WindowState = FormWindowState.Normal
    End If
  End Sub
#End Region
  
End Class
dipa ahuja replied to jenn on 17-Dec-11 02:42 PM
M surprised to see that you are not getting the error while comparing text with DateTime???

Here in your if condition, you must convert the String into DateTime before comparing it with the string

Private Sub Timer1_Tick(ByVal sender As System.ObjectByVal e As System.EventArgs)
    For Each item As ListViewItem In Listview1.Items
      Dim dtCheck As DateTime = DateTime.Parse(item.SubItems(0).Text.ToString())
      Dim dtCheck2 As DateTime = DateTime.Parse(item.SubItems(1).Text.ToString())
      If dtCheck = System.DateTime.Now AndAlso dtCheck2 = DateTime.Today Then
        Interaction.MsgBox(item.SubItems(2).Text)
      End If
      If item.SubItems(0).Text = System.DateTime.Now And item.SubItems(1).Text = TimeOfDay Then
        Interaction.MsgBox(item.SubItems(2).Text)
      End If
    Next
 
  End Sub
  
and clearify you query in simple word. don't say what you have done , and what you want now.

Just post question from starting , assume you haven't done anything from beginning what you actually want to do?
jenn replied to dipa ahuja on 20-Dec-11 08:10 AM
thank you :), dipa ahuja

i have not been able to get back in here to check the forum for a bit of days now- and i have not tried your solution. but after reading it i about slapped myself stupid (which wouldnt have been to hard LOL)

i do see what your saying, and see now where i been just kinda completely avoiding comparing anything at all LOL!!!
have not been at this long- am kinda a newbie in the field. about a year or so- so it was not plain to me, and thank you for your help :)- will let you know how it turned out!