Wednesday, March 28, 2012

VLISP Housecleaning: Example 2

Here is another example from my ebook, "The Visual LISP Developer's Bible, 2011 Edition" (Amazon Kindle).  This one demonstrates a shell process, whereby the code executes an external COM interface request to use VBscript to perform a simple date calculation.

(defun daysold (d / sc cmd result)
    (setq sc (vlax-create-object "ScriptControl"))
    (vlax-put-property sc 'Language "vbscript") 
    (setq cmd (strcat "DateDiff(\"d\", \"" d "\", Now)" )) 
    (setq result (vlax-invoke-method sc 'Eval cmd)) 
    (vlax-release-object sc) 
    (eval result) 
)

(setq age (daysold "12/1/2010"))

You can do the same with JavaScript (actually JScript) as well.

No comments: