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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying 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

Suggested Solutions

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

808 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