Results 1 to 2 of 2

Thread: Sort Date Time

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Sep 2000
    Location
    Jacksonville
    Posts
    23

    Arrow

    Does someone have a readymade procedure for sorting out
    date time?
    I have to find out which is the latest file added to the directory(which is continously getting files into it).
    So I need to compare the DateCreated of each of the files at any time to find out the latest entry

  2. #2
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    'Imagine there are easier ways but this works.
    Code:
    Option Explicit
    
    Sub SortMeOut(iArray As Variant)
    'sort the array
         Dim lLoop1 As Long
         Dim lLoop2 As Long
         Dim lTemp As String
              
      
         For lLoop1 = UBound(iArray) To LBound(iArray) Step -1
           For lLoop2 = LBound(iArray) + 1 To lLoop1
    
             If iArray(lLoop2 - 1) > iArray(lLoop2) Then
               lTemp = iArray(lLoop2 - 1)
               iArray(lLoop2 - 1) = iArray(lLoop2)
               iArray(lLoop2) = lTemp
             End If
           Next lLoop2
         Next lLoop1
       End Sub
    
    'uses List1 (listbox) and Command1 (command button)
    'file information using File Scripting Object (fso)
    'date created.
    
    
     Private Sub Form_Load()
    
    List1.Clear
    
    Dim stFile As String
    Dim stDir As String
    Dim fso As Object
    Dim myArrDate()
    Dim myArrFile()
    Dim i As Integer
    Dim temp As String
    Dim mylen As Integer
    
    Set fso = CreateObject("Scripting.FileSystemObject")
    
    stDir = "C:\My Documents\"
    stFile = Dir$(stDir & "*.*")
    
    Do While stFile <> ""
    'if you want to access each file you must use the dir
    'and the file
    stFile = stDir & stFile
    
    'store info in array for sorting purposes
     ReDim Preserve myArrDate(i)
        temp = Right(Format(fso.GetFile(stFile).DateCreated, "YYYMMDD"), 8)
        myArrDate(i) = temp & stFile & Format(fso.GetFile(stFile).DateCreated, "YYYYMMDD")
        i = i + 1
      stFile = Dir
      Loop
    'sort
      Call SortMeOut(myArrDate)
      
    'list after sort from A-Z order
      For i = LBound(myArrDate) To UBound(myArrDate)
         mylen = Len(myArrDate(i))
         temp = Right(myArrDate(i), mylen - 8)
         List1.AddItem temp
         Next i
    
    End Sub
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

Posting Permissions

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



Click Here to Expand Forum to Full Width