DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 7 of 7

Thread: trial application

  1. #1
    Join Date
    Mar 2005
    Posts
    51

    trial application

    Hi

    ...I need again your help. Please, could you say me a way to make my application a trial?
    I try to use a ini file where I put the date when the application opened...but I don't find the way to know when the application opened for the first time.
    If you are so kind, please tell me another solution...

  2. #2
    Join Date
    Jul 2008
    Posts
    2
    不知道你说什么

    GetPrivateProfileString Function
    http://msdn.microsoft.com/en-us/library/ms724353.aspx

  3. #3
    Join Date
    Aug 2004
    Location
    Orange, California
    Posts
    1,263
    This code should help, but you will have to edit it to work with your application:
    Code:
    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
    
    Public 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
    
    Public Sub LaunchMain()
      Dim DaysLeft As Integer
      If Not AppRegistered Then
        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 Registration Form here
            ' make sure registration form terminated before continuing
            Form2.Show vbModal, Me
            ' If everything Is ok the registration form should
            ' Use: 'AppSetRegistered True' to register the program
            ' and then unload itself
     
            If AppRegistered Then
              'Open the Main Form Here
              Form1.Show
            End If
          End If
          ' Unload this form, which will terminate
          ' your program if no other forms were opened.
          ' That is if the registration form was exited without
          ' registering the application, so the Main Form never opened
          Unload Me
        Else
          MsgBox "You have " & DaysLeft & " " & IIf(DaysLeft = 1, "day left", "days left") & " to use this program.", vbInformation
          'Open the Main From Here  - still have time left
          Form1.Show
        End If
      Else
        'Open Main Form Here Program Is Registered
        Form1.Show
      End If
    End Sub

  4. #4
    Join Date
    Mar 2005
    Posts
    51
    Thanks xk82180316 and Ron.
    Could you tell me if it's posible to know when the user opened for the first time my application?

  5. #5
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,663
    Ron Weller's example does exactly that.
    Code:
     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
    That does it right there.

  6. #6
    Join Date
    Aug 2004
    Location
    Orange, California
    Posts
    1,263
    If you add these two lines of code to the Trial Period Routine, then the Public Variable IsFirstTime will be true the very first time the program is run, and false any other time.
    Code:
    Public IsFirstTime As Boolean
    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
        IsFirstTime = True
        SaveSetting App.Title, "Trial Period", "Date Start", Date
      Else
        TrialPeriodDaysLeft = DateDiff("d", DateStart, Date) > DaysTrial
      End If
    End Function
    
    Public 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
    
    Public Sub LaunchMain()
      Dim DaysLeft As Integer
      If Not AppRegistered Then
        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 Registration Form here
            ' make sure registration form terminated before continuing
            Form2.Show vbModal, Me
            ' If everything Is ok the registration form should
            ' Use: 'AppSetRegistered True' to register the program
            ' and then unload itself
     
            If AppRegistered Then
              'Open the Main Form Here
              Form1.Show
            End If
          End If
          ' Unload this form, which will terminate
          ' your program if no other forms were opened.
          ' That is if the registration form was exited without
          ' registering the application, so the Main Form never opened
          Unload Me
        Else
          MsgBox "You have " & DaysLeft & " " & IIf(DaysLeft = 1, "day left", "days left") & " to use this program.", vbInformation
          'Open the Main From Here  - still have time left
          Form1.Show
        End If
      Else
        'Open Main Form Here Program Is Registered
        Form1.Show
      End If
    End Sub

  7. #7
    Join Date
    Mar 2005
    Posts
    51
    Thanks everybody and have a nice weekend!

Similar Threads

  1. Replies: 1
    Last Post: 01-11-2007, 05:16 AM
  2. Wrap or 'host' an application within another?
    By diddydustin in forum .NET
    Replies: 0
    Last Post: 11-08-2006, 11:37 AM
  3. Inventory Management Application Using VB
    By Krishna in forum vb.announcements
    Replies: 0
    Last Post: 11-26-2002, 12:03 AM
  4. Capturing mouse clicks outside VB Application
    By Sunil in forum VB Classic
    Replies: 0
    Last Post: 07-28-2000, 08:43 PM
  5. Application vs. Web Servers
    By Matt in forum Web
    Replies: 1
    Last Post: 06-12-2000, 06:24 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center