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.
Independent Software Vendors: 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

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 …
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

752 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