Solved

Sorting a List Box Descending  ie Latest to Top

Posted on 2003-11-13
8
325 Views
Last Modified: 2010-05-01
Is there a simple way of sorting a list box  (DESC).
Ie I need to have the list box sort the latest to the top.
ie
20031212 asasasaas
20031111 m,m,mm,sm,

The option in the list box seems to only allow  sort assending???
0
Comment
Question by:turnerrob
  • 3
  • 3
  • 2
8 Comments
 
LVL 4

Expert Comment

by:Clothahump
ID: 9743013
Select your recordset in descending order and load the list box that way.
0
 

Author Comment

by:turnerrob
ID: 9743039
I am loading a directory listing into the list box, ie i do not have a recordset, sorry i did not mention this.
0
 
LVL 4

Assisted Solution

by:Clothahump
Clothahump earned 63 total points
ID: 9743050
Ok, load the directory listing into an array, sort the array descending, then load the list box.
0
 
LVL 11

Accepted Solution

by:
bingie earned 62 total points
ID: 9743073
Here is how to sort an array in descending order

Option Explicit

Private Sub Command1_Click()
   Dim MyArray
   MyArray = Array("A", "Z", "M")
   Call SortDecending(MyArray)
   Debug.Print MyArray(0); MyArray(1); MyArray(2)
End Sub

Private Function SortDecending(a)
   Dim i, j As Long
   Dim tmp
   For i = 1 To UBound(a)
       For j = 0 To UBound(a)
           If LCase(a(i)) > LCase(a(j)) Then
               temp = a(j)
               a(j) = a(i)
               a(i) = temp
           End If
       Next
   Next
   SortDecending = a
End Function

(thx to Erick37 for above)
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:turnerrob
ID: 9743079
I thought this may be the only way.!!
Appreciate the advice., thanks for your help

regards turnerrob
0
 

Author Comment

by:turnerrob
ID: 9743124
Appreciate both the help comments offered.
Have split points, hope this is ok.

regards  turnerrob
0
 
LVL 4

Expert Comment

by:Clothahump
ID: 9743150
Glad to help!
0
 
LVL 11

Expert Comment

by:bingie
ID: 9743161
Anytime!
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

757 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

22 Experts available now in Live!

Get 1:1 Help Now