Solved

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

Posted on 2007-03-21
3
151 Views
Last Modified: 2010-04-23
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
Comment
Question by:ddrudik
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 63

Accepted Solution

by:
Fernando Soto earned 500 total points
ID: 18765654
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
 
LVL 27

Author Comment

by:ddrudik
ID: 18766537
Perfect.  Thanks.
0
 
LVL 63

Expert Comment

by:Fernando Soto
ID: 18766585
Not a problem, glad I was able to help. ;=)
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question