Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 188
  • Last Modified:

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.
0
Jimbo1954
Asked:
Jimbo1954
  • 4
  • 4
1 Solution
 
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
        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
 
Jimbo1954Author Commented:
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
 
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.
0
Technology Partners: 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!

 
Jimbo1954Author Commented:
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
 
käµfm³d 👽Commented:
Is it possible to show the code that converts the date to the number as seen in the file?
0
 
Jimbo1954Author Commented:
CLng([expiry])*1954

expiry is the date in a database
0
 
käµfm³d 👽Commented:
And the type of the DB column is date? Or is it varchar or similar?
0
 
nepaluzCommented:
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
 
Jimbo1954Author Commented:
thanks
worked like a charm
Jimbo
0

Featured Post

Technology Partners: 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!

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now