|
-
Jul 10th, 2000, 02:05 PM
#1
Thread Starter
Lively Member
Can anyone point me in the right direction of how to sort an array of filenames. In my program I am trying to read in a list of filenames from a directory?
Thanks Scott
-
Jul 10th, 2000, 02:10 PM
#2
_______
<?>
Code:
'sort and arry by alpha
'Remember when sorting alpha...ab5 is greater than ab49
'this example uses listboxes for display purposes only
'Put 2 list boxes and a command button on a form
'command1,list1,list2
'
'add a bas module and put this code in it
'
Sub BubbleSortStrings(iArray As Variant)
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
'+++++++++++++++++++++++++++++++++++++++++++++++++++
'Put this in the click or load or whatever
' ++++++++++++++++++++++++++++++++++++++++++++++++++
Dim iArray(0 To 9) As String
Dim iLoop As Integer
Randomize
For iLoop = LBound(iArray) To UBound(iArray)
iArray(iLoop) = "ab" & Int(Rnd * 100)
List1.AddItem iArray(iLoop)
Next iLoop
Call BubbleSortStrings(iArray)
For iLoop = LBound(iArray) To UBound(iArray)
List2.AddItem iArray(iLoop)
Next iLoop
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
-
Jul 10th, 2000, 03:23 PM
#3
aaarggh, no, no and thrice no!!!
bubble sort is ludicrously slow!
if you are interested in a far faster method, email me and I'll send you a DLL i made a while ago to do exactly this job.
-
Jul 10th, 2000, 03:34 PM
#4
transcendental analytic
Bubble sort get's exponentially slower the more items you have in your array, this method performs aritmetically:
Code:
Sub Sort_shell(a() As String)
Dim n&, i&, j&, k&, h
n = UBound(a)
k = n \ 2
While k > 0
For i = 0 To n - k
j = i
While (j >= 0) And (a(j) > a(j + k))
h = a(j)
a(j) = a(j + k)
a(j + k) = h
If j > k Then
j = j - k
Else
j = 0
End If
Wend
Next i
k = k \ 2
Wend
End Sub
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|