OberonPlace.com Forums  

Go Back   OberonPlace.com Forums > Developer Forums > VBA > CorelDRAW/Corel DESIGNER VBA

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 04-02-2005, 09:05
Rick Randall
Guest
 
Posts: n/a
Default How can I make a macro time out?

What is the best way to make a macro time out?
I have a macro that will be used globally but don't want them to be able to use it forever. I wrote in some code that times out the macro based on the system date. Unfortunately, in other countries they set their system clock formats differently so my code doesn't work on their pc's. What's a good way to do this?
Reply With Quote
  #2  
Old 04-02-2005, 10:06
shelbym's Avatar
shelbym shelbym is offline
Senior Member
 
Join Date: Nov 2002
Location: Cheyenne, WY
Posts: 1,770
Blog Entries: 10
Send a message via ICQ to shelbym Send a message via AIM to shelbym Send a message via MSN to shelbym Send a message via Yahoo to shelbym
Default

Rick I am working on a macro and would like to do the same thing. Maybe the all knowing Alex can help us out. Thanks,

Shelby
Reply With Quote
  #3  
Old 04-02-2005, 10:55
Rick Randall
Guest
 
Posts: n/a
Default

Alex can never be stumped
Reply With Quote
  #4  
Old 05-02-2005, 00:30
Alex's Avatar
Alex Alex is offline
Administrator
 
Join Date: Nov 2002
Posts: 1,940
Blog Entries: 4
Default

Well, here is a small piece of code which will not work after, say, Jan 1, 2006:

Code:
Sub MyMacro()
    If Date > DateSerial(2006, 1, 1) Then
        MsgBox "Sorry, this function expired", vbCritical
        Exit Sub
    End If
    ' Do something
End Sub
As you can see, you can use the function Date to return the current system date and DateSerial to construct a date by specifying the year, month, and day number.

You can do a lot of interesting things with dates. For example, you can subtract two dates to determine the difference in days between them. You can use this in your macro too:

Code:
Sub MyMacro2()
    Dim Expiry As Date
    Expiry = DateSerial(2005, 1, 1)
    If Date > Expiry Then
        MsgBox "Sorry, this function expired " & (Date - Expiry) & " days ago", vbCritical
        Exit Sub
    End If
    ' Do something
End Sub
Reply With Quote
  #5  
Old 07-02-2005, 08:59
Rick Randall
Guest
 
Posts: n/a
Default

will this code work if they have european time? example: 2005/02/07
i would like for this to work globally.
Reply With Quote
  #6  
Old 07-02-2005, 23:02
Alex's Avatar
Alex Alex is offline
Administrator
 
Join Date: Nov 2002
Posts: 1,940
Blog Entries: 4
Default

Yes, the "Date" data type is locale invariant. However when you print the date, it will appear differently on different locales. Or if you use the "#" notation to represent a date, such as in:

Code:
Sub DateExample()
    Dim d As Date
    d = #2/7/2005#
    MsgBox Format$(d, "mmmm d, yyyy")
End Sub
Then this notation is locale-aware and could mean either February 7th, or July 2nd, depending on your OS settings. However I intentionally used the DateSerial function which is always predictable.
Reply With Quote
  #7  
Old 09-02-2005, 11:16
shelbym's Avatar
shelbym shelbym is offline
Senior Member
 
Join Date: Nov 2002
Location: Cheyenne, WY
Posts: 1,770
Blog Entries: 10
Send a message via ICQ to shelbym Send a message via AIM to shelbym Send a message via MSN to shelbym Send a message via Yahoo to shelbym
Default

My concern was if the user changes there system date back a few days they could easily fool the expire date. So here is what I come up with:

Code:
If IsNull(ActiveDocument.Properties("GraniteFills", 1)) = True Then
    ActiveDocument.Properties("GraniteFills", 1) = Date
ElseIf ActiveDocument.Properties("GraniteFills", 1) < Date Then
    ActiveDocument.Properties("GraniteFills", 1) = Date
End If

Dim Expiry As Date
    Expiry = DateSerial(2005, 2, 9)
    If ActiveDocument.Properties("GraniteFills", 1) > Expiry Then
        MsgBox "Your copy of the Granite Fills program expired " & (ActiveDocument.Properties("GraniteFills", 1) - Expiry) & " days ago.", vbCritical, "Granite Fills"
        Exit Sub
    End If
I know there are still ways around this, but is adds one more level of security.

Thanks,

Shelby
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Someone make an Active List Font macro dungbtl CorelDRAW/Corel DESIGNER VBA 8 28-10-2019 09:53
Trying to get my Time Recording script running... johndankey CorelDRAW/Corel DESIGNER VBA 12 26-04-2004 22:48
An Idea for a handy and easy to make macro vallentin Macros/Add-ons 2 16-03-2004 11:35
New macro to clip curves w.r.t. a border Gerard Hermans Macros/Add-ons 0 09-06-2003 07:50
Speeding up a macro Rick Randall CorelDRAW/Corel DESIGNER VBA 2 12-12-2002 10:51


All times are GMT -5. The time now is 02:16.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright © 2011, Oberonplace.com