Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Reading a txt-file with license-code
I'm thinking of making software add-in in VBA for MS Excel.
I will 'rent' this add-ins out and send my clients a new license-code every month after the bills are paid. This license-code is (at least now in the beginning) planned to be emailed over in txt files (which the client has to store in their "My Documents"). Inside the file, with the name "license-code.txt" a license-code like dk3-3kk-555-777 would be found. So to have this license-code being 'useful' I need to program a function which check whether the valid license-code is in place or not (toward current month). I plan to put in the function enough license-codes to cover the next 10 years, so the total of text-code which needs to be searched will be 10 x 12 months = 120 license-codes. Now we are at the core of my question: Will this way of doing the licence check result in a slow working code (I assume Select case will be used)? (- anyone who have samples of such code?) Thanks, JohS |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Reading a txt-file with license-code
Several things come to mind. First, be aware that someone proficient
with VBA and sufficiently motivated can get around any sort of licensing requirements. Next, I would include the expiration date within the license key itself. You don't want to distribute all the keys to the user and you don't want to have to read through and parse out 120 keys every time the user opens the file. Unnecessary overhead. Just take the serial date of the expiration date and scramble it amid some meaningless characters. E.g., xDxxxxDxxxxxDDxDxxx where x are some arbitrary characters and the D's are digits of the serial date. For example, the string 13t5e49a245a9532s20 encodes the number 39952 which is the serial date of 19-May-2009. While this isn't NSA-level coding, it will be sufficient for 99.9% of the end users. For simplicity, I would put the license text file in the same directory as the XLA file, rather than in My Documents (whose name and location varies by OS version and locale). Then you can use code like Function IsValidKey() As Boolean Dim FName As String Dim FNum As Integer Dim S As String Dim T As String Dim D As Date On Error GoTo ErrH: FName = ThisWorkbook.Path & "\Test.txt" FNum = FreeFile Open FName For Input Access Read As #FNum Line Input #FNum, S Close #FNum T = Mid(S, 2, 1) & Mid(S, 7, 1) & Mid(S, 13, 2) & Mid(S, 16, 1) D = CDate(CLng(T)) If D < Now Then IsValidKey = False Else IsValidKey = True End If Exit Function ErrH: IsValidKey = False End Function With this code in place, you can call it from the Workbook_Open event and if it returns False, kick the user out of the program. Private Sub Workbook_Open() Dim B As Boolean B = IsValidKey() If B = False Then MsgBox "Your license has expired.", vbOKOnly ThisWorkbook.Close savechanges:=False End If End Sub Cordially, Chip Pearson Microsoft Most Valuable Professional Excel Product Group, 1998 - 2009 Pearson Software Consulting, LLC www.cpearson.com (email on web site) On Sat, 18 Apr 2009 22:34:06 +0200, "JohS" wrote: I'm thinking of making software add-in in VBA for MS Excel. I will 'rent' this add-ins out and send my clients a new license-code every month after the bills are paid. This license-code is (at least now in the beginning) planned to be emailed over in txt files (which the client has to store in their "My Documents"). Inside the file, with the name "license-code.txt" a license-code like dk3-3kk-555-777 would be found. So to have this license-code being 'useful' I need to program a function which check whether the valid license-code is in place or not (toward current month). I plan to put in the function enough license-codes to cover the next 10 years, so the total of text-code which needs to be searched will be 10 x 12 months = 120 license-codes. Now we are at the core of my question: Will this way of doing the licence check result in a slow working code (I assume Select case will be used)? (- anyone who have samples of such code?) Thanks, JohS |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
reading txt file and copying the lines in new excel file | Excel Programming | |||
reading from another file and pasting to current file, "combobox" | New Users to Excel | |||
reading data from 2nd file in 1st file using Combobox | Excel Programming | |||
Reading complete Excel using DDE code | Excel Programming | |||
reading from text file to excel file | Excel Programming |