Announcement

Collapse
No announcement yet.

Creating an expiration date function

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Creating an expiration date function

    Hey all,

    I've been looking through the form but I can't seem to find what I'm looking for. I want to set an expiration date and then every time my addin is ran check the date. If the current date equals or is greater than the expiration date lock the program.

    I was thinking like setting the end date in the windows registry at some point and then checking the dates to validate.

    Also does anyone have any ideas how I can only set the date once (like at first run of the addin) and every other time only check the date instead of setting the end date all over again?

    How can I do something like this?

    Thank you

  • #2
    Re: Creating an expiration date function

    Use the GetSetting function to retreive the cut off date from the registry. If it does not exists then this is the first time and you can use savesetting to store a date.
    If it does exist then you can test to see if todays date is within limits.

    As for the cut-off date you could store that either as a constant in your code or as a calculated date from first use or even a custom document property.

    Cheers
    Andy

    Comment


    • #3
      Re: Creating an expiration date function

      I am looking at the function in the help file and I do'nt really understand what is needed or how it works. Can you please explain it to me? More so the arguments required.


      Code:
      GetSetting(appname, section, key[, default])
      Thank you
      Last edited by bwells; August 25th, 2006, 01:31.

      Comment


      • #4
        Re: Creating an expiration date function

        This example checks for a valid entry if it is exists then checks are made.
        If not it is added.

        Option Explicit

        Private Const m_BWELL_ADDIN_APPNAME = "Bwell_PPT_Addin"
        Private Const m_BWELL_ADDIN_APPSECTION = "Usage"
        Private Const m_BWELL_ADDIN_APPKEY = "Expiry"
        Sub Demo()

        Dim vntRegItem As Variant

        vntRegItem = GetSetting(Appname:=m_BWELL_ADDIN_APPNAME, _
        Section:=m_BWELL_ADDIN_APPSECTION, _
        Key:=m_BWELL_ADDIN_APPKEY, _
        Default:="")
        If vntRegItem = "" Then
        ' no information stored yet so do now
        vntRegItem = Format(Now() + 3, "dd-mmm-yyyy") ' 3 days from now
        SaveSetting Appname:=m_BWELL_ADDIN_APPNAME, _
        Section:=m_BWELL_ADDIN_APPSECTION, _
        Key:=m_BWELL_ADDIN_APPKEY, _
        Setting:=vntRegItem

        Else
        ' have information stored so test it
        If Now() > CDate(vntRegItem) Then
        MsgBox "This addin has expired", vbCritical Or vbOKOnly, "Addin Expired"
        End
        Else
        MsgBox "This addin has " & CLng(CDate(vntRegItem) - Now) + 1 & " days left", _
        vbExclamation Or vbOKOnly, "Addin Expiry Warning"
        End If
        End If

        ' uncomment to clear entry from reg.
        ' DeleteSetting m_BWELL_ADDIN_APPNAME, m_BWELL_ADDIN_APPSECTION

        End Sub

        Cheers
        Andy

        Comment


        • #5
          Re: Creating an expiration date function

          What do they aruguments mean? Like what is wanted to be passed to the function?

          Comment


          • #6
            Re: Creating an expiration date function

            The names are of your own creating and can be whatever you want.

            The registry is constructed like a folder view.
            The Appname is the top level folder within the area of the registry that these functions write to.
            The section name is a subfolder and the Keys are items within a subfolder.

            In order to see a graphical view of the registry use the program regedit.exe in your windows folder. You can then use F3 to search for the appname. The structure should then become clearer.

            Please note that manually playing around in the registry can cause problems.

            Cheers
            Andy

            Comment


            • #7
              Re: Creating an expiration date function

              Hey thanks alot, I understand how this works now. I think i got it working. Thanks for the help.

              Comment


              • #8
                Re: Creating an expiration date function

                Question about expiry date systems:

                With most software that have expiry dates, when the user recieves they're new version (lets say valid for another year) is the old expiry date set in the registy delete and then a new one is added? Or does it stay there and programmers just add a new date?

                Comment


                • #9
                  Re: Creating an expiration date function

                  I would have thought that most would just replace the current exipry date with the new one.

                  One possible problem is the scenario where if the addin filename changes it would be possible to use both the new and old versions of the addin.

                  Cheers
                  Andy

                  Comment

                  Working...
                  X