Hello,

I am finishing up a program in VB that edits, saves, and adds data to a listview via textboxes. The listview data is stored on the harddrive via a txt file. One of the columns in the listview is a birthday in a DD/MM/YYYY format. I want to have a pop-up window when I load the program that lets me know the First and Last Name (which are the first two columns in listview) of everyone with birthdays coming up in 7 days, 2 days, & today.

Can anyone point me to a reference for this or have the code?

Thanks. I am new here I will make more use of the search bar. I wasn't aware of the universal time function, though I don't care about the time just the date. I suppose when I use the date compare function that won't matter though.

I know about loops and if/else etc.. but the main question I was asking which I don't see answered anywhere is comparing it to a specific listview column. So my subitem(6) is my date. How would I do that?

use a loop to go through each row of the listview, save the column you want to check in a temp variable and then do whatever date compare you want to do with that variable.

then if the date fits the criterias save the other columns needed to display your messages in a list, and when you are done looping the listview, display your reminders in whatever way you plan to display them by looping through this saved list.

'heres a rough pseudocode~

'loop list view
    'save date column
    'compare dates
    'if date matches
        'save other columns in remindersList
    'end if
'end loop

'display reminder section
'loop reminderList
    'display reminder info
'end loop
'end display section

if you loop through the items in the listview, possibly a For Each loop, you can compare the subitem to a date. You might have to parse it into a datetime type to do the comparison. If the date qualifies save the whole item in a separate list. This way you have access to any of the info in the item you might need. You could then iterate through this list and add each name, birth date etc., ended with a newline, to a string then display the whole thing in a messagebox.

Those seem like interesting ways to do it.. Saving it to another list would work, but probably inefficient..

I think another solution I just thought of is having the list sorted on the form load by current date forward. So if anyone has a birthday today it puts it at the top of the list and then so on.. I already have the code to allow me to sort the columns so I would just need to add in a sort based on the date when it's loaded... I might go with this route.

if you don't like the list idea and you're only going to get the info once, you could build your string directly instead of going to a list first. I suggested a list, in case you wanted to save the info or do something more that just display a reminder.

One way to consider, I assume you're iterating through the textfile to load the data. You could easily check the birthday subitem at that time to display the reminder.

I see what you are saying. I am working on some code now to loop through the subitem, after checking for the right date format. I will then have it pop-up in a message box..

Edited 3 Years Ago by pandeter: Realized I'm a dummy

Here is what I have so far, and it isn't catching matching dates:

Dim Loopz As Integer
Dim subz As String

Loopz = ListView1.Items.Count

    For i = 0 To Loopz
        subz = ListView1.Items(0).SubItems(3).Text

        If DateValue(subz) = Today() Then

MsgBox(ListView1.Items(0).Text & " " & ListView1.Items(0).SubItems(1).Text & "; ", MsgBoxStyle.OkOnly)

        End If

    Next

Edited 3 Years Ago by pandeter

I also can't seem to get this to work.. On the = today() line it shows my form rather than showing the message.. Any reason why?

Dim Z As Int32

            If ListView1.Items.Count > 0 Then
                For Z = 0 To ListView1.Items.Count
                    If ListView1.Items(Z).SubItems(3).Text = Today() Then

                        MsgBox("Hi")
                    End If
                Next Z
            End If

Alright guys.. I finally am almost finished. My only problem is I have to make it look at only the month and day.. I am having issues with that. Here is my code so far:

Dim loopz As Integer

        loopz = ListView1.Items.Count

        For i = 0 To loopz

            Dim edate = ListView1.Items(i).SubItems(3).Text

            Dim format() = {"dd/MM/yyyy", "d/M/yyyy", "dd-MM-yyyy"}

            Dim expenddt As Date
            Date.TryParseExact(edate, format,
                System.Globalization.DateTimeFormatInfo.InvariantInfo,
                Globalization.DateTimeStyles.None, expenddt)

            If CStr(Today().AddDays(3)) = edate Then

                MsgBox(ListView1.Items(0).Text & " " & ListView1.Items(0).SubItems(1).Text & ", " & " msg " & Today().AddDays(3), MsgBoxStyle.OkOnly)

            End If
        Next

Try this

Dim format() = {"dd/MM/yyyy", "d/M/yyyy", "dd-MM-yyyy"}
Dim loopz As Integer = ListView1.Items.Count
'A string variable to hold the messagebox message
Dim MessageboxString as String = ""
For i = 0 To loopz
    Dim edate = ListView1.Items(i).SubItems(3).Text
    Dim expenddt As Date
    Date.TryParseExact(edate, format, System.Globalization.DateTimeFormatInfo.InvariantInfo, Globalization.DateTimeStyles.None, expenddt)

    If Today.AddDays(3).Month = expenddt.Month And Today.AddDays(3).Day = expenddt.Day Then
        'Build a string in case you get more than one person with a birthday that day
        MessageboxString += ListView1.Items(i).Text & " " & ListView1.Items(i).SubItems(1).Text & ", " & " msg " & expenddt.ToLongDateString & vbNewLine
    End If
Next
'Display a messagebox with everyones name that has a birthday that day
MsgBox(MessageboxString)

Edited 3 Years Ago by tinstaafl

That looks great! The only issue I had was I had to add .tostring at the end of line 6 above after .text otherwise it was throwing an exception for some reason..

Yes, that was it.. I also added an if messageboxstring <> "" then show the message. Otherwise it was popping up a blank message no matter what.

Thanks for the help!

This article has been dead for over six months. Start a new discussion instead.