This fairly short piece of code allows the program to check whether a trial period of any length has expired, notifying the user how many days are left. The user is given the option to register the program or just not use it any more. It uses the VB registry setting functions. Encryption can be added when saving to the registry so that almost nobody at all can use the program for longer than the trial period.
Option Explicit
Private Const TRIAL_PERIOD_DAYS As Integer = 30
Private Function TrialPeriodDaysLeft(DaysTrial As Integer) As Integer
Dim DateStart As Date
DateStart = GetSetting(App.Title, "Trial Period", "Date Start", 0)
If DateStart = 0 Then
SaveSetting App.Title, "Trial Period", "Date Start", Date
Else
TrialPeriodDaysLeft = DateDiff("d", DateStart, Date) > DaysTrial
End If
End Function
Private Sub AppSetRegistered(Registered As Boolean)
SaveSetting App.Title, "Trial Period", "Registered", Registered
End Sub
Private Function AppRegistered() As Boolean
AppRegistered = GetSetting(App.Title, "Trial Period", "Registered", False)
End Function
Private Sub Form_Load()
If Not AppRegistered Then
Dim DaysLeft As Integer
DaysLeft = TrialPeriodDaysLeft(TRIAL_PERIOD_DAYS)
If DaysLeft < 0 Then
If MsgBox("The trial period for " & App.Title & " has expired." & vbCrLf & _
"Would you like to register to continue using this program?", vbQuestion + vbYesNo) = vbYes Then
' Open up order form here
' Use: 'AppSetRegistered True' to register program
Else
' Exit your program here
End If
Else
MsgBox "You have " & DaysLeft & " " & IIf(DaysLeft = 1, "day left", "days left") & " to use this program.", vbInformation
End If
End If
End Sub
Comments