serial number and date

Hi Guys

  i have created a tsv file that contains two fields per line, to use as a licence file

001060d2f234      80112046
001060d2f235      80117908
001060d2f236      80164804
001060d2f237      80299630
001060d2f238      80176528

the first is a Mac address, the second is a numeric date of expiry

I want to compare the mac address with the list, if it is in the list, then check the date to see if it is less than today, if it is then run the program, if not then lock the program
also if it is not in the list lock the program

can somebody please help me with some code to achieve the above.
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

käµfm³d 👽Commented:
I'd say something like this:

Module Module1

    Sub Main()
        Dim keys As New Dictionary(Of String, DateTime)

        Using reader As New System.IO.StreamReader("licenses.txt")
            While Not reader.EndOfStream
                Dim line As String = reader.ReadLine()
                Dim parts() As String = line.Split(vbTab)
                Dim convertedDate As DateTime

                If parts.Length > 1 AndAlso _
                   ConvertDate(parts(1), convertedDate) Then
                    keys.Add(parts(0), convertedDate)
                End If
            End While
        End Using

        Dim targetMac As String = "001060d2f235"

        If keys.ContainsKey(targetMac) AndAlso keys(targetMac) < DateTime.Now Then
            ' run program
            ' lock program
        End If
    End Sub

    Function ConvertDate(ByVal value As String, ByRef outDate As DateTime) As Boolean
        Return (True)
    End Function

End Module

Open in new window

I don't know what your format is for your datetime values above, so I merely stubbed out a function to convert the value to an actual DateTime object. Change that bit of logic to fit your environment.
Jimbo1954Author Commented:  thankyou

the mac address is an actual mac address of a blutooth device used as a dongle

the date is a date ie 27/03/2012 converted to clng then multiplied  by a number, i did it that way so it is not obvious that it is a date, the fields are separated by a tab and the row is separated by Crlf. does this affect the above code in anyway??

käµfm³d 👽Commented:
does this affect the above code in anyway??
You should just have to reverse that logic and put it inside of ConvertDate. Other than that, no it shouldn't change. ReadLine takes care of your CrLf, and Split with VbTab takes care of the tab.
Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

Jimbo1954Author Commented:

struggling with where to put the code to convert the date back
i need to divide it by the number which will bring me back to the clng conversion
then i need to convert from clng date to a normal date format..........????
käµfm³d 👽Commented:
Is it possible to show the code that converts the date to the number as seen in the file?
Jimbo1954Author Commented:

expiry is the date in a database
käµfm³d 👽Commented:
And the type of the DB column is date? Or is it varchar or similar?
I assumed that your dates are OADates but get future dates after applying your logic! (see image at the end)
Having said that, here is a code suggestion to your question
        Dim TestMAC As String = "001060d2f236"
        'first and foremost, dis-able the program
        Using sr As New FileIO.TextFieldParser("pathToFile") With {.Delimiters = {vbTab}}
            While Not sr.EndOfData
                Dim line = sr.ReadFields()
                If line(0).ToString.Trim = TestMAC Then
                    If DateTime.FromOADate((CLng(line(1)) / 1954)) < Date.Today Then
                        'enable the program
                        'disable the program
                    End If
                    Exit While
                End If
            End While
        End Using

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Jimbo1954Author Commented:
worked like a charm
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.