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
149 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 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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

Suggested Solutions

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

831 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