Results 1 to 2 of 2

Thread: Excel Short Date in DateLastModified in Scripting.FileSystemObject

  1. #1
    Past Vice President / AUGI Volunteer peter's Avatar
    Join Date
    2000-09
    Location
    Honolulu HI
    Posts
    1,109
    Login to Give a bone
    0

    Default Excel Short Date in DateLastModified in Scripting.FileSystemObject

    (I found an error in this code and fixed it)

    I was thinking about marking blocks inside drawings with the file size and date last modified of the original block drawing.

    That way I can make sure they are the most current and can make the drawing update them if they are not.

    Also it has always seemed silly to me that symbols forget those parameters in a drawing.

    Well I started playing with DateLastModified in the scripting.filesystemobject.

    As it turns out the value is actually the Excel Short Date, which starts from Jan 1 1900
    (it has a bug because 1900 had 365 days not 366 as Excel has it)

    I tried a couple of the functions available to determine the year, month, day, hour, min, sec 1/100sec from that value and there were bugs around year ends etc...

    So I rewrote them and have tested them and they seem to be accurate.

    For your inspection...

    Syntax:

    Code:
    (Filedate "312vg.dwg")
    Returns

    Code:
    '(2013 12 16 7 14 9 99)
    Code:
    ;___________________________________________________________________________________________________________ 
    ;
    ; Function to get the lastdatemodified of a file.
    ;___________________________________________________________________________________________________________
    
    (defun FileDate (strFileName / lstSizeDate)
     (if (setq lstSizeDate (FileDateAndSize (findfile strFileName)))
      (datetimeconvert (cadr lstSizeDate))
     )
    )
    
    ;___________________________________________________________________________________________________________ 
    ;
    ; Function to convert Excel Short Date Number to a list of Year, Month, Day, Hour, Minute, Second, 1/100 Sec.
    ;___________________________________________________________________________________________________________
    
    (defun DateTimeConvert (sngDateTime / intDays lstQuad sngTime)
     (if (and 
          (setq intDays       (fix sngDateTime))
          (setq lstTime       (DecimalTimeConvert (remainder sngDateTime)))
          (setq lstQuad       (QuadDay (- intDays (* 1461 (/ intDays 1461)))))
         )
      (mapcar '+ lstQuad
                 (list (+ 1900 (* 4 (/ intDays 1461))) 0 0 0 0 0 0)
                 lstTime
      )
     )
    )
    
    ;___________________________________________________________________________________________________________ 
    ;
    ; Function to convert a decimal day into hours, minutes, seconds and 1/100 Seconds.
    ;___________________________________________________________________________________________________________
    
    (defun DecimalTimeConvert (sngDecimal / lstReturn sngTime)
     (setq lstReturn (list 0 0 0))
     (foreach intTime (list 24 60 60 100)
      (setq sngTime    (* sngDecimal intTime))
      (setq sngDecimal (remainder sngTime))
      (setq lstReturn  (cons (fix sngTime) lstReturn))
     )
     (reverse lstReturn)
    )
    
    ;___________________________________________________________________________________________________________ 
    ;
    ; Function to return the non-whole number portion of a real number
    ;___________________________________________________________________________________________________________
    
    (defun Remainder (sngValue / sngRemainder)
     (if (>= (setq sngRemainder (- sngValue (fix sngValue))) 1.0)
      (setq sngRemainder 0.0)
      sngRemainder
     )
    )
    
    ;___________________________________________________________________________________________________________ 
    ;
    ; Function to divide a 4 year leap year cycle and return the year, month, and day as a list in that cycle
    ;___________________________________________________________________________________________________________
    
    (defun QuadDay (intDays / lstDays lstYearAndDay)
     (if (= intDays 0)
      (list -1 12 31 0 0 0 0)
      (progn
       (setq lstYearAndDay (member< intDays (list 0 366 731 1096))) 
       (if (= (car lstYearAndDay) 1)
        (setq lstDays (list 0 31 60 91 121 152 182 213 244 274 305 335)) ; <-Leap Year
        (setq lstDays (list 0 31 59 90 120 152 182 212 243 273 304 334)) 
       )
       (append (cons (1- (car lstYearAndDay)) (member< (cadr lstYearAndDay) lstDays)) (list 0 0 0 0))
      )
     )
    )
    
    ; Function to iterate through a list and remove items greater than supplied value.
    ; The return value is a differnt list with the truncated list length and maximum value.
    
    ;___________________________________________________________________________________________________________ 
    ;
    ; Function to iterate through a list and remove items greater than supplied value.
    ; The return value is a differnt list with the truncated list length and maximum value.
    ;___________________________________________________________________________________________________________
    
    (defun Member< (Number lstNumbers / lstReturn)
     (foreach intNumber (reverse lstNumbers)
      (if (>= Number intNumber)
       (setq lstReturn (cons intNumber lstReturn))
      )
     )
     (list (length lstReturn)
           (- Number (apply 'max lstReturn))
     )
    )
    
    ;___________________________________________________________________________________________________________ 
    ;
    ; Function to return the Date and Size of a selected file full name
    ;___________________________________________________________________________________________________________
    
    (defun FileDateAndSize (strFullName / lstReturn objFIle )
     (if(and
         (setq objFile (vlax-invoke objGlobalFileSystem "getfile" strFullName))
         (setq lstReturn (list (vlax-get objFile "Size")
                               (vlax-get-property objFile "DateLastModified")))
         (errortrap '(vlax-release-object objFile))
        )
      lstReturn
     )
    )
    
    ;___________________________________________________________________________________________________________ 
    ;
    ; Function to define a global variable for the "Scripting.FileSystemObject"
    ;___________________________________________________________________________________________________________
    
    (or objGlobalFileSystem (setq objGlobalFileSystem (vlax-create-object "Scripting.FileSystemObject")))
    
    
    ;___________________________________________________________________________________________________________ 
    ;
    ; Standard Errortrap Function
    ;___________________________________________________________________________________________________________
    
    (defun ErrorTrap (symFunction / objError result)
     (if (vl-catch-all-error-p
          (setq objError (vl-catch-all-apply
                         '(lambda (XYZ)(set XYZ (eval symFunction)))
                          (list 'result))))
      nil
      (if result result 'T)
     )
    )
    (vl-load-com)
    Attached Files Attached Files
    Last edited by peter; 2015-05-27 at 05:06 AM.
    AutomateCAD

  2. #2
    Past Vice President / AUGI Volunteer peter's Avatar
    Join Date
    2000-09
    Location
    Honolulu HI
    Posts
    1,109
    Login to Give a bone
    0

    Default Re: Excel Short Date in DateLastModified in Scripting.FileSystemObject

    I found an error in the code above and fixed it. FYI
    AutomateCAD

Similar Threads

  1. Scripting from AutoCAD?
    By jasonp in forum AutoLISP
    Replies: 3
    Last Post: 2014-06-26, 08:02 PM
  2. Excel Date Extraction
    By LSElite in forum AutoLISP
    Replies: 7
    Last Post: 2013-05-27, 08:26 AM
  3. "Scripting.FileSystemObject" Documentation
    By BlackBox in forum AutoLISP
    Replies: 5
    Last Post: 2010-10-06, 06:01 PM
  4. MS Excel date formatting
    By Maverick91 in forum Software
    Replies: 4
    Last Post: 2008-11-20, 10:20 PM
  5. Scripting.FileSystemObject - Runtime Error
    By kdayman in forum VBA/COM Interop
    Replies: 4
    Last Post: 2004-10-15, 03:42 PM

Posting Permissions

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