Solved

filelistbox > name and date sort

Posted on 2003-12-07
3
1,122 Views
Last Modified: 2012-06-27
I want to be able to sort a filelistbox (named file1) ascending and descending at name and date.

How can that be achieved ?
0
Comment
Question by:saskia
  • 2
3 Comments
 
LVL 6

Expert Comment

by:prasitlee
ID: 9891963
Dear saskia,
    If you are using ListBox as the control for showing file, try to change the property "Sorted" to TRUE. All files in FileListBox would be sorted as you needed.
                                                      Meng
0
 
LVL 5

Accepted Solution

by:
mccainz2 earned 125 total points
ID: 9892150
Well , don't think you should use a fileList box for this , I wrote a quickie app using a regular listbox .... code follows
Modify the sort string to get your desired results .

Private Sub Command1_Click()

    If Not LoadFiles("C:\DX9\Lib") Then
        MsgBox "Files failed to load."
    End If
   
End Sub


Private Function LoadFiles(sFolder As String)

    Dim objFSO As New FileSystemObject
    Dim objFile As File
    Dim objFolder As Folder

    Dim dDate As Date
    Dim objRetRS As New ADODB.Recordset
    Dim strFilter As String
   
    LoadFiles = False
   
    objRetRS.CursorLocation = adUseClient
    objRetRS.ActiveConnection = Nothing
   
    'Set up our columns etc....
   
    objRetRS.Fields.Append "FileName", adVarChar, 250
    objRetRS.Fields.Append "FileDate", adDate
   
    objRetRS.Open
   
    If objFSO.FolderExists(sFolder) Then
        Set objFolder = objFSO.GetFolder(sFolder)
    Else
        GoTo err_exit
    End If
   
    For Each objFile In objFolder.Files
        objRetRS.AddNew
            objRetRS.Fields("FileName") = objFile.Name
            objRetRS.Fields("FileDate") = objFile.DateLastModified
        objRetRS.Update
    Next
   
    objRetRS.Sort = "FileDate,FileName"
    objRetRS.MoveFirst
   
    While Not (objRetRS.EOF)
        List1.AddItem objRetRS("FileName")
        objRetRS.MoveNext
    Wend
   
    LoadFiles = True
   
err_exit:
End Function
0
 
LVL 5

Expert Comment

by:mccainz2
ID: 9892159
Regarding sybtax for Ascending and descending sorting ...
For example
 objRetRS.Sort = "FileName DESC,FileDate ASC"
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
VB6 add a minute to the date time value 8 61
Copy a row 12 57
How to hault or freeze parent form when a 2d form is open in vb6 3 36
Protecting vb6 & .Net code Obfuscation 18 94
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now