Loading
Ozgrid Excel Help & Best Practices Forums

Excel Video Tutorials / Excel Dashboards Reports



Results 1 to 9 of 9

Thread: Creating an expiration date function

  1. #1
    Join Date
    30th May 2006
    Location
    Kitchener, Ontario
    Posts
    120

    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

    Excel Video Tutorials / Excel Dashboards Reports


  2. #2
    Join Date
    7th March 2003
    Location
    Essex, England
    Posts
    11,310

    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


  3. #3
    Join Date
    30th May 2006
    Location
    Kitchener, Ontario
    Posts
    120

    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.


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

    Excel Video Tutorials / Excel Dashboards Reports


  4. #4
    Join Date
    7th March 2003
    Location
    Essex, England
    Posts
    11,310

    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.

    VB:
    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


  5. #5
    Join Date
    30th May 2006
    Location
    Kitchener, Ontario
    Posts
    120

    Re: Creating an expiration date function

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

    Excel Video Tutorials / Excel Dashboards Reports


  6. #6
    Join Date
    7th March 2003
    Location
    Essex, England
    Posts
    11,310

    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


  7. #7
    Join Date
    30th May 2006
    Location
    Kitchener, Ontario
    Posts
    120

    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.

    Excel Video Tutorials / Excel Dashboards Reports


  8. #8
    Join Date
    30th May 2006
    Location
    Kitchener, Ontario
    Posts
    120

    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?

    Excel Video Tutorials / Excel Dashboards Reports


  9. #9
    Join Date
    7th March 2003
    Location
    Essex, England
    Posts
    11,310

    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


Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Possible Answers

  1. Date Function - NOW Function - Excel 2007 NOW Function
    By Dave Hawley in forum Excel Formulas (No Questions)
    Replies: 0
    Last Post: July 10th, 2008, 03:32
  2. Spreadsheet expiration date?
    By mramsey in forum EXCEL HELP
    Replies: 9
    Last Post: September 30th, 2005, 23:36
  3. Replies: 2
    Last Post: August 14th, 2005, 14:07
  4. Insert a row based on an expiration date
    By dbrown2867 in forum EXCEL HELP
    Replies: 10
    Last Post: September 26th, 2004, 14:51

Bookmarks

Posting Permissions

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