Visual Basic 6 File List Boxes time and date sorting

In VB6 filelistboxes sort the files alphabetically I need to be able to sort them by date and time created.
Preferrably with the oldest file at the top of the list and the newest file at the bottom. It needs to be quick and I do not want to use databases.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

You will need to replace the filelistbox with a standard listbox and list the files inside a directory by yourself. Scan thru the directory for files, get the filesizes, sort, add to list. poc. The point is that don't get stuck with the filelistbox, use a listbox instead. All the neccessary code samples can be found at
Depending on what you are doing, you could try the browser control instead of the file list box...

'using the browser dialog box
'make a reference

Option Explicit

Private Const MAX_PATH = 260

Private Declare Function SHBrowseForFolder Lib _
"shell32" (lpbi As BrowseInfo) As Long

Private Declare Function SHGetPathFromIDList Lib _
"shell32" (ByVal pidList As Long, ByVal lpBuffer _
As String) As Long

Private Declare Function lstrcat Lib "kernel32" _
Alias "lstrcatA" (ByVal lpString1 As String, ByVal _
lpString2 As String) As Long

Private Type BrowseInfo
   hWndOwner As Long
   pIDLRoot As Long
   pszDisplayName As Long
   lpszTitle As Long
   ulFlags As Long
   lpfnCallback As Long
   lParam As Long
   iImage As Long
End Type

Private Sub Form_Load()
'Opens a Browse Folders Dialog Box that displays the
'directories in your computer
Dim lpIDList As Long ' Declare Varibles
Dim sBuffer As String
Dim szTitle As String
Dim tBrowseInfo As BrowseInfo

szTitle = "Hello World. Click on a directory and " & _
"it's path will be displayed in a message box"
' Text to appear in the the gray area under the title bar
' telling you what to do

With tBrowseInfo
   .hWndOwner = Me.hWnd ' Owner Form
   .lpszTitle = lstrcat(szTitle, "")
End With

lpIDList = SHBrowseForFolder(tBrowseInfo)

If (lpIDList) Then
   sBuffer = Space(MAX_PATH)
   SHGetPathFromIDList lpIDList, sBuffer
   sBuffer = Left(sBuffer, InStr(sBuffer, vbNullChar) - 1)
'          <<< Add Your Code Here >>>
                 MsgBox sBuffer
    End If
End Sub

Forget Filelistbox. Use a Listview (in the Common Controls OCX). This is what is used in thw Windows Explorer (the pane on the right).
To fill the listview with data you can/should use the FileSystemObject. To use this you have to add a reference to Microsoft Scripting Runtime (SCRRUN.DLL). Once you've added this reference add the following lines in your code to use the FileSystemObject:

dim fsoMain as FileSystemObject
Set fsoMain = new FileSystemObject

The FileSystemObject contains datatypes like Drive, File, Folder, Subfolder,...
It is incredibly easy to get information about paths, files, folders,...

You will need to program a little bit but it is realy fun to use because this is what is missing in standard VB.

When you need more info, send me a mail ( I'll send you an example project.

BTW: With not more than 30 lines of code you can program your own light weight explorer with this baby.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

"You will need to program a little bit but it is realy fun to use because this is what is missing in standard VB. "

Nope, it's all there, you just have to use what's on top of your shoulders..
To VbMaster:

Have you ever used FileSystemObject ? If not, try it. You will see how much simpler it is.
Yes, I did try it once  when a 'expert' here said that his code using the FileSystemObject was faster than pure VB code, just to prove that he was wrong. ;)

A big dependency file, problems with version compatibiliy, bad performance.. I do not see ANY reason why to use it when everything it does can be implemented using a small amount of VB code.

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.