VBA
Discuss AutoCAD ActiveX and VBA (Visual Basic for Applications) questions here.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

expiry date for trial macro

11 REPLIES 11
Reply
Message 1 of 12
Anonymous
692 Views, 11 Replies

expiry date for trial macro

I am looking for a couple of lines of code which will check the current date and if it is before then ok if the date is 29/12 or past the msg box "trial has expired" displays.
I have got this far but dont know what to do in the highlighted lines see Sub NewId
Thanks in anticipation
At this stage disregard the function foo below as this sets expire and gets current date ok
jb

Function foo()
Dim ExpireDate As String
Dim CurrentDate As String
ExpireDate = "20091130.0634455"
CurrentDate = ThisDrawing.GetVariable("cdate")
End Function

Sub NewId()
ExpireDate = "20091130.0634455" 'set expire date
CurrentDate = ThisDrawing.GetVariable("cdate") 'get current date

how do i check current date against expire date next line

If "CurrentDate" is ???????????????????????????????? before "ExpireDate" Then 'compare two dates
MsgBox "success"
Else
MsgBox "Your trial has expired"
End If
End Sub
11 REPLIES 11
Message 2 of 12
Anonymous
in reply to: Anonymous

Hi, try dimensioning as Date and you can also use the Date() function to return the current date. Hope this helps

Sub gf()
Dim x As Date
x = "11/30/2009"
If Date > x Then MsgBox "expired"
End Sub
Message 3 of 12
Anonymous
in reply to: Anonymous

Talk about timing...

i was researching the same issue, can somebody plz clarify the following(easy on me):

1-When you close VBA all the variables reset(Yes? or No?)
2-What date to you get from getvariable(cdate), if it is the system's, then the user can change the time on the PC and use your code without limits, if not, plz explain what it is.
3-How can we know, in VBA, the date the code was used for the first time? don't we need more control.
4-i had two options,
4.1-Record the date of the first use of the code, and then compare to the current date
4.2-Count the number of times the code ran and compare to a constant (i think this would be easier)
5-I thought of creating a file in a hidden location on the customer pc via vba, writing the counter to that file each time the file is ran, then comparing, but that also have setbacks, what if the user doesn't have enough control to create the file, what if the file is deleted...

I appreciate your feedback,
Message 4 of 12
Anonymous
in reply to: Anonymous

Hi wayz ,

You have two choices for storing the previous run information whether it
be the number of runs or a first run date.

You can write it to a file
You can write it to the registry

In the first case any computer literate person can find the file within
a few minutes of searching, so you need to put encrypted data in the
file. If the file is deleted, then you can stop the program from running.

If you write to the registry it will require a higher level of knowledge
to find your data, but it will still be findable, so you need to encrypt
again.

Depending on the value of breaking your system and the likely interest
in doing so, someone somewhere will break it.

You have to balance the cost to you of them breaking it, with the
additional cost of having more complex systems to make it harder to break.

Regards,


Laurie Comerford


wayz wrote:
> Talk about timing...
>
> i was researching the same issue, can somebody plz clarify the
> following(easy on me):
>
> 1-When you close VBA all the variables reset(Yes? or No?)
> 2-What date to you get from getvariable(cdate), if it is the system's,
> then the user can change the time on the PC and use your code without
> limits, if not, plz explain what it is.
> 3-How can we know, in VBA, the date the code was used for the first
> time? don't we need more control.
> 4-i had two options,
> 4.1-Record the date of the first use of the code, and then compare to
> the current date
> 4.2-Count the number of times the code ran and compare to a constant
> (i think this would be easier)
> 5-I thought of creating a file in a hidden location on the customer pc
> via vba, writing the counter to that file each time the file is ran,
> then comparing, but that also have setbacks, what if the user doesn't
> have enough control to create the file, what if the file is deleted...
>
> I appreciate your feedback,
Message 5 of 12
Anonymous
in reply to: Anonymous

Thank's Laurie for the reply,

in fact i wrote a code(VBA) for a company, that code will save their engineers a lot of time(hence $$$$$), they are willing to buy it from me, but they need to test it first, the code generates automated drawings using forms and dynaminc blocks. I can't just hand them the code, i need to protect myself somehow, can you point me to the right direction.

Regards,
Message 6 of 12
Anonymous
in reply to: Anonymous


Maybe you could use a watermark approach?  Add
some big ugly "DEMO" text to the drawing.
Message 7 of 12
Anonymous
in reply to: Anonymous

Hi wayz,

Since the program is unique for their company, you are only dealing with
one client and it is clearly someone you can talk with.

You do not want to spend any significant effort on security for one
client only

While they could bypass the suggestion below by changing the computer
date - this is quite unlikely in a company environment as many other
aspects of their computing are likely to be related to the computer date.

Tell them you will supply a demonstration version which will expire
after a certain date.

In the demonstration version.

Make sure the file name includes the word demo:

When you start the program call the Function "Warning" with code like
If Warning = False then Exit Sub
{code}
Public Const Expirydate = "1/1/2010"

Private Function Warning() As Boolean
If Finalise = True Then
If MsgBox("This is a demonstration version only." & vbCrLf & "It
will expire on " _
& Expirydate & vbCrLf & "DO NOT use for production work" &
vbCrLf _
& "Do you wish to continue?", vbYesNo) = vbYes Then
Warning = True
Else
Warning = False
End If
Else
Warning = False
End If

End Function

Private Function Finalise() As Boolean
If Date > CDate(Expirydate) Then ' You will need to check the syntax
for this comparison
MsgBox "This is a demonstration version only." & vbCrLf & "It has
expired and will be removed", vbCritical

' Now remove the file from their computer.
Kill ThisDrawing.Application.VBE.ActiveVBProject.fileName
Finalise = False
Else
Finalise = True
End If
End Function
{code}

You could call this function at other places in the code as well -
depending on the level of trust you have for your client. Also adjust
the message to suit your sensibilities.



Regards,


Laurie Comerford


wayz wrote:
> Thank's Laurie for the reply,
>
> in fact i wrote a code(VBA) for a company, that code will save their
> engineers a lot of time(hence $$$$$), they are willing to buy it from
> me, but they need to test it first, the code generates automated
> drawings using forms and dynaminc blocks. I can't just hand them the
> code, i need to protect myself somehow, can you point me to the right
> direction.
>
> Regards,
Message 8 of 12
norman.yuan
in reply to: Anonymous

Displaying a warning message might be sufficient enough in such a "weak" protection approach. Using "Kill [FileName"] statement to delete currently loaded DVB file probably will not work: the file is opened in current Acad session (and possibly by other users if the DVB file is in a network share) and cannot be deleted. If the exception is not handled, the "Kill...." statement will simply crash the VBA program. Well, that might be just what the OP wants: crash the VBA program if the time expires.

Norman Yuan

Drive CAD With Code

EESignature

Message 9 of 12
Anonymous
in reply to: Anonymous

Hi Norman,

I must admit I did not test the "Kill" part of the code. 🙂

It was added as a sort of after thought merely to increase the
inconvenience level to the user of attempting to run the code after it
expired.

How far to go with a 'weak' system is entirely dependent on the
relationship between the OP and their client.




Regards,


Laurie Comerford

norman.yuan wrote:
> Displaying a warning message might be sufficient enough in such a "weak" protection approach. Using "Kill [FileName"] statement to delete currently loaded DVB file probably will not work: the file is opened in current Acad session (and possibly by other users if the DVB file is in a network share) and cannot be deleted. If the exception is not handled, the "Kill...." statement will simply crash the VBA program. Well, that might be just what the OP wants: crash the VBA program if the time expires.
>
Message 10 of 12
Anonymous
in reply to: Anonymous

Forget what Laurie just told you. That is about as lame as it gets.

It's a simple matter to defeat that by setting the system clock back (and
resetting it before saving a file to get the correct file date). Many users
that defeat time-limited demos using nothing more complicated than the
system clock will use scripts to change the time when they need to, which
makes it very easy.

You can get the true date from the internet. Of course, that requires the
system running the demo app have an internet connection, which is quite
reasonable for a demo.

{code}

Function InternetGetDate() As String

Dim URL As String
Dim dat As String
Dim datStart As Integer
Dim datEnd As Integer
Dim oHttpTest As Object

Set oHttpTest = CreateObject("Microsoft.XMLHTTP")
URL = "http://www.time.gov/timezone.cgi?Central/d/-6"
oHttpTest.Open "POST", URL, False
oHttpTest.Send

If CLng(oHttpTest.Status) < 300 Then
datStart = InStr(oHttpTest.responseText, " " color=" & Chr(34) & "white" & Chr(34) & ">") + 116
datEnd = InStr(datStart, oHttpTest.responseText, "
")
dat = Mid(oHttpTest.responseText, datStart, datEnd - datStart)
InternetGetDate = dat
Else
InternetGetDate = "Error: " & oHttpTest.statusText
End If
Set oHttpTest = Nothing
End Function

Public Sub TestInternetGetDate()
Dim sDate As String
sDate = InternetGetDate()
MsgBox sDate
End Sub

{code}

There are many ways to get the date & time from the internet. The above code
is really just serves to demonstrate that it can be done, but isn't
necessarily the best way to do it.

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD
Supporting AutoCAD 2000 through 2010

http://www.acadxtabs.com

Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");

wrote in message news:6299360@discussion.autodesk.com...
Thank's Laurie for the reply,

in fact i wrote a code(VBA) for a company, that code will save their
engineers a lot of time(hence $$$$$), they are willing to buy it from me,
but they need to test it first, the code generates automated drawings using
forms and dynaminc blocks. I can't just hand them the code, i need to
protect myself somehow, can you point me to the right direction.

Regards,
Message 11 of 12
Anonymous
in reply to: Anonymous

Thank you all for the replies,

Laurie, we are not in an ideal world, otherwise, the complete demo concept wouldn't exist.

I think i'm gonna invest on this one, and once i find a way, i'll use it on all my demo codes, because in the near future, i'll be proposing codes to companies, and then, it'll be crucial to have a solid safety piece of code... (Thought also about an EULA, but too cumbersome...)

So far, i agree with Tony, but i was thinking how to make it work if the pc cannot connect to the internet, but Tony made a good point, on a demo version, i can put some restrictions, this may speed up their testing phase...:-)

Once again,
Thanks,
Message 12 of 12
Anonymous
in reply to: Anonymous

{quote}

in the near future, i'll be proposing codes to companies,
I would consider migrating to VB.NET

{quote}

I would seriously consider migrating to VB.NET, because
it is unwise to invest in VBA based solutions at this point in
the game.

If you were using VB.NET, the VB.NET code at the link
below gets the current date and time from the internet in
a more robust way (accurate to +/- 10 milliseconds).

http://www.caddzone.com/InternetDateTime.vb

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD
Supporting AutoCAD 2000 through 2010

http://www.acadxtabs.com

Email: string.Format("{0}@{1}.com", "tonyt", "caddzone");

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost