Solved

serial number and date

Posted on 2012-03-28
9
178 Views
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.
0
Comment
Question by:Jimbo1954
  • 4
  • 4
9 Comments
 
LVL 74

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
        Else
            ' 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.
0
 

Author Comment

by:Jimbo1954
ID: 37778733
Wow..........fast  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??

Thanks
Jimbo
0
 
LVL 74

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.
0
 

Author Comment

by:Jimbo1954
ID: 37778854
hmm

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..........????
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 74

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?
0
 

Author Comment

by:Jimbo1954
ID: 37778944
CLng([expiry])*1954

expiry is the date in a database
0
 
LVL 74

Expert Comment

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

Accepted Solution

by:
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
                    Else
                        'disable the program
                    End If
                    Exit While
                End If
            End While
        End Using

Open in new window

res_dates
0
 

Author Closing Comment

by:Jimbo1954
ID: 37841689
thanks
worked like a charm
Jimbo
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

757 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now