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
145 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
  • 2
3 Comments
 
LVL 62

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 62

Expert Comment

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

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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 …
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

744 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now