LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 201
Default Problem sorting file dates in an array

I have read through the various posting trying to get this sorted and found a
bubble sort from Tom Ogilvy, but its not working. Can somene work out what I
may have done wrong? The full code is below:

Private FileNameList(1 To 20, 1 To 2), FileListCount As Integer


Sub Test_File_Date_Sort()
Call GetFileList("C:\temp", FileNameList, FileListCount)
For x = 1 To FileListCount
Cells(x + 2 + FileListCount, "A").Value = FileNameList(x, 2)
Cells(x + 2 + FileListCount, "B").Value = FileNameList(x, 1)
Next
End Sub

Sub GetFileList(GF_Folder As String, FileNameList, FileListCount)
' Complile a list of files in a folder that are sorted oldest to newest

Dim fso As Object
Dim folder As Object
Dim File As Variant

Set fso = CreateObject("Scripting.FileSystemObject")
Set folder = fso.GetFolder(GF_Folder)
FileListCount = 0

' Load the array with the file name and the date for each file found in
the specific directory
If folder.Files.Count 0 Then
For Each File In folder.Files
FileListCount = FileListCount + 1
FileNameList(FileListCount, 1) = File
FileNameList(FileListCount, 2) = FileDateTime(File)

Cells(FileListCount, "A").Value = FileNameList(FileListCount, 2)
Cells(FileListCount, "B").Value = FileNameList(FileListCount, 1)

Next File
End If

SortArray (FileNameList)
End Sub

Function SortArray(myArray)
' Tom Ogilvy bubble sort (modified)
' This sort simply takes a 2 dimentional and sorts the value install in
the second element
Dim temp, i, j, k

For i = LBound(myArray, 1) To UBound(myArray, 1) - 1
For j = i + 1 To UBound(myArray, 1)
If myArray(i, 2) myArray(j, 2) Then
For k = LBound(myArray, 2) To UBound(myArray, 2)
temp = myArray(i, k)
myArray(i, k) = myArray(j, k)
myArray(j, k) = temp
Next
End If
Next
Next

SortArray = myArray
End Function

This is the ouput which suggests that no sort happened at all???

2008 05 02 13:48 file1
2008 05 06 15:08 file2
2008 05 06 15:09 file3
2008 05 06 15:25 file4
2008 05 02 13:45 file5
2008 04 30 08:27 file6
2008 04 30 09:10 file7
2008 05 01 13:00 file8
2008 05 02 13:44 file9
2008 05 02 13:38 file10
2008 05 02 13:40 file11
2008 04 30 08:13 file12


2008 05 02 13:48 file1
2008 05 06 15:08 file2
2008 05 06 15:09 file3
2008 05 06 15:25 file4
2008 05 02 13:45 file5
2008 04 30 08:27 file6
2008 04 30 09:10 file7
2008 05 01 13:00 file8
2008 05 02 13:44 file9
2008 05 02 13:38 file10
2008 05 02 13:40 file11
2008 04 30 08:13 file12

Any ideas?

--
Trefor
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Sorting Cells that contain an Array as Dates StaceyJ Excel Discussion (Misc queries) 1 February 3rd 09 12:58 AM
problem custom sorting a date in an excel file clcnewtoaccess Excel Discussion (Misc queries) 1 January 16th 09 06:15 PM
Problem with sorting 19th century dates Robert Judge Excel Worksheet Functions 2 January 8th 07 02:17 AM
problem with dates in csv file saybut Excel Discussion (Misc queries) 2 November 11th 05 02:03 PM
Problem sorting 2-D array RB Smissaert Excel Programming 1 December 1st 04 09:57 PM


All times are GMT +1. The time now is 09:39 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"