Results 1 to 1 of 1

Thread: Trial Version Timed Tutorial

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Nov 2016
    Posts
    95

    Post Trial Version Timed Tutorial

    Hello! Welcome to this hopefully correct tutorial. Now, before we begin, I would like to say that this is the first tutorial I have done. Secondly, the first part of this tutorial was not found by me but simply a YouTube video I will a credit later. Thirdly, if you have any questions/suggestions then please comment them as I would like to learn/see what you come up with. This tutorial is meant to be easy but not crackproof. Should hopefully suite basic needs of a trial system, that is all. Now, ready to begin?

    Name:  settings.jpg
Views: 866
Size:  18.1 KB
    Alright so you would first want to go to settings. To get there, click on solution explorer then click on the name of project(Should have a VB symbol to the left of it) and click properties. Then click settings. Now, you will want to create five variables. You can make the names anything but here is what I used:
    TrialActive and TrialUsed As Booleans and both equal False.
    StartDate As Date
    FirstTime As Boolean that equaled True
    TotalTimeSeconds As Integer and that equals however long the trial is in seconds(Will explain why I did this in a bit)

    TrialActive simply lets the application know that the Trial is currently active.
    TrialUsed will be false until the program says it is true(Will be explained in a bit)
    StartDate will be used to record when the Trial First begins
    FirstTime is optional but I used firsttime because I wanted it to be all done in the formload event, not a button like the video I got this from used.
    TotalTimeSeconds is basically a "safeguard" in case the person using the trial decides to change the date to try and get a longer period of testing.

    Alright, so now that we have all that done, time to get into the code.

    You will want to double click the form to bring up the formload event.
    *Credit for this part of the tutorial: https://www.youtube.com/watch?v=agu9dFa4LzE&t=2s
    Code:
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            'My.Settings.Reset()
            If (My.Settings.FirstTime = True) Then
                My.Settings.FirstTime = False
                My.Settings.TrialActive = True
                My.Settings.StartDate = Date.Today
                My.Settings.TrialUsed = False
                My.Settings.Save()
                MessageBox.Show("Your Trial period will end in 7 days")
                tmrTotalTimeTrial.Start()
            ElseIf (My.Settings.FirstTime = False) Then
                If (My.Settings.TrialActive = True) Then
                    CheckDate()
                    tmrTotalTimeTrial.Start()
                End If
                If (My.Settings.TrialUsed = True Or My.Settings.TotalTimeSeconds <= 0) Then
                    tmrTotalTimeTrial.Stop()
                    MsgBox("Your trial period has ended. Please purchase the software to continue using.", MsgBoxStyle.Information, "Trial Period Ended")
                    Me.Close()
                End If
            End If
        End Sub
    The firsttime will only be used one time and that is when the application is started for the first time ever. That is why we went with application settings because we can save these settings and not have to worry about creating an external file that the user can change whenever he/she wants too. The timer used is for the safeguard being used which will be explained in a bit. Now, I also used an If Elseif statement because whenever the user opens the application again, the firsttime variable will be false so it will check to see if it is false and when it is it will go to the If (My.Settings.TrialActive = True) statement. When the trial is over it will then search for the If (My.Settings.TrialUsed = True) statement. (I suppose you could use an ElseIf statement here as well but at the time I didn't) then whenever the user tries to use the application after the trial has ended. The user will be prompted with a MsgBox that is stating that the trial has ended and will need to buy the software and after the user presses Okay the application will close. Now, we need to make a Sub Method for CheckDate.

    In the code, create a Sub Method and for the tutorial, we are gonna call it CheckDate()

    Code:
     Sub CheckDate()
            Dim dt As Date = My.Settings.StartDate
            Dim days As Double = (Date.Now.AddDays(-7).Subtract(dt)).TotalDays
            If (days <= 0) Then
                My.Settings.TrialActive = True
                My.Settings.Save()
            Else
                My.Settings.TrialActive = False
                My.Settings.TrialUsed = True
                MsgBox("Your trial period has ended. Please purchase the software to continue using.", MsgBoxStyle.Information, "Trial Period Ended")
                Me.Close()
            End If
        End Sub
    We firstly want to create two variables. dt and days. dt will represent the My.Settings.StartDate and days will represent the Date now. Where it says (-7), be sure to keep that number negative. That number could be any number you want as long as it is negative. That number is representing the trial days that you choose to have. If days is less than or equal to 0 then the trial is active but if that variable is more than 0 then the trial is over.(That is the else statement)

    Finally, we need to get in with the timer. So, create a timer and set the internal value to 1000. I named my timer TmrTotalTimeTrial but you can name yours whatever you like.

    After you create the timer, double click on it to bring you into the code of it.

    Code:
        Private Sub tmrTotalTimeTrial_Tick(sender As Object, e As EventArgs) Handles tmrTotalTimeTrial.Tick
            Dim minusone As Integer = 1
            My.Settings.TotalTimeSeconds = My.Settings.TotalTimeSeconds - minusone
            My.Settings.Save()
           ' MsgBox(My.Settings.TotalTimeSeconds)
            If (My.Settings.TotalTimeSeconds <= 0) Then
                tmrTotalTimeTrial.Stop()
                MsgBox("Your trial period has ended. Please purchase the software to continue use.", MsgBoxStyle.Information, "Trial Period has ended")
                Me.Close()
            End If
        End Sub
    We need to firstly make a new variable, I named it minusone. That variable needs to equal one.
    I then just put My.Settings.TotalTimeSeconds = My.Settings.TotalSeconds - minusone
    Then you need to put after that My.Settings.Save
    I put the MsgBox there simply to test to see if it works so you can leave that part out unless you wanna see it work.
    Now, the next part is to put an If statement in checking to see if My.Settings.TotalTimeSeconds <=0 because the one above only goes on Formload event so this is the an extra catch.(Suppose with this, you don't need the one listed earlier but it doesn't matter)
    Be sure to stop the timer in the If statement because if you don't then you will get just repeated MsgBoxes and you don't want that.

    Well, that concludes this tutorial. Hopefully I didn't make this confusing to you guys. If you have any questions/suggestions then post a reply. Thanks and have a good day!


    ****SHORT NOTES TO REMEMBER****
    Code:
     Dim days As Double = (Date.Now.AddDays(-7).Subtract(dt)).TotalDays
    the number, that is where (-7) is, must be equal to the amount of seconds. In order to find the amount of seconds within a day just do this:
    60*60 = 1Hour or 3,600 seconds.
    24 * 3600 = 1 day or 86,400
    x = # of trial days
    (for tutorial, x = 7)
    86,400 * x or 7 = 604,800 seconds in seven days.

    The reason I went with seconds is that I believe it will be the most accurate. You could do minutes of hours but seconds I think would be most beneficial to you.
    Last edited by Dragnorian; May 25th, 2017 at 12:31 PM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width