[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 157
  • Last Modified:

Removing multiple lines in a text file based on a date calculation in one of the lines (part 2)

I have a text file with multiple entries formatted as:

        Name: x
         DOB: mm/dd/yy
 Name Number: x
Court Number: x
        Race: x
        Eyes: x
      Height: x
         Sex: x
        Hair: x
         Wgt: x
      Issued: x
     Expires: x
Process Type: x
 Crime Class: x
  Wanted for: x

Previously I had asked a question regarding text replacement based on the DOB:
http://www.experts-exchange.com/Programming/Languages/.NET/Visual_Basic.NET/Q_21611130.html

FernandoSoto answered that question, which I do appreciate his assistance with that.  Unfortuantely I am running into a possible complication, I need to have any records where the individual is less than 18 years old on day the report is run to be removed from the text file.  

The code works except that where the individual's DOB year is 18 years ago but their DOB month/day is later than today's date, which would technically make that person less than 18 years old, which I need to remove from my text file.

Starting with the code from the previous solution I am looking for the month/day to be included in the DOB check to exclude those records where the individual is less than 18 years old on the day the report is run.

Thanks in advance for your help.
0
ddrudik
Asked:
ddrudik
  • 2
1 Solution
 
Fernando SotoCommented:
Hi ddrudik;

I have modified the function to return the correct number of years.

    Private Function RemoveUnder18(ByVal m As Match) As String

        Dim separator As Integer = m.Value.IndexOf("/"c)
        Dim DOB As DateTime = DateTime.Parse(m.Value.Substring(separator - 2, 10))
            Dim ReptDate As DateTime = Now
            
        ' The number of years between the two years
        Dim yearsTotal As Integer = ReptDate.Year - DOB.Year

        ' Check to see if the ending month is less then the starting month
        ' or that the ending month equals the starting monthat and that the
        ' ending day is less then starting day. Then subtract 1 from the
        ' yearsTotal.
        If ReptDate.Month < DOB.Month OrElse (ReptDate.Month = _
            DOB.Month AndAlso ReptDate.Day < DOB.Day) Then
            yearsTotal -= 1
        End If

        If yearsTotal < 18 Then
            Return ""
        Else
            Return m.Value
        End If

    End Function

Fernando
0
 
ddrudikAuthor Commented:
Perfect.  Thanks.
0
 
Fernando SotoCommented:
Not a problem, glad I was able to help. ;=)
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now