serial number and date

Posted on 2012-03-28
Last Modified: 2012-04-13
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.
Question by:Jimbo1954
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
  • 4
  • 4
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 37778671
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.

Author Comment

ID: 37778733  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??

LVL 75

Expert Comment

by:käµfm³d 👽
ID: 37778772
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.
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

ID: 37778854

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..........????
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 37778908
Is it possible to show the code that converts the date to the number as seen in the file?

Author Comment

ID: 37778944

expiry is the date in a database
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 37779613
And the type of the DB column is date? Or is it varchar or similar?
LVL 17

Accepted Solution

nepaluz earned 500 total points
ID: 37781643
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


Author Closing Comment

ID: 37841689
worked like a charm

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

It’s quite interesting for me as I worked with Excel using for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
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 (…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

626 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