Sort Array (without WordBasic)

D

D

After a bit of troubleshooting, I have discovered that the
WordBasic.SortArray command automatically truncates all entries in the array
to 255 characters, upon sorting. So, it now looks like I need to find
another way to sort an array, as the array I am using has a field that will
often be longer than 255 characters. Anyone have any ideas?

Thanks a lot.
 
H

Helmut Weber

Hi D,
Sub BubbleSort()
Dim i As Long
Dim j As Long
Dim k As Long
Dim aBuf As String
With ComboBox1
k = .ListCount
For j = 0 To k - 1
For i = (j + 1) To (k - 1)
If .List(i) < .List(j) Then
aBuf = .List(j)
.List(j) = .List(i)
.List(i) = aBuf
End If
Next i
Next j
End With
End Sub
Whether it is a plain array or an array as a combobox
or a listbox doesn't matter. If you want to know more
about sorting, google for mergesort, quicksort, shakersort,
heapsort, etc. Kind of science of its own.
BTW, wordbasic.sortarray doesn't sort correctly anway.
http://www.google.de/groups?hl=de&lr=&ie=UTF-8&selm=#[email protected]
by Howard Kaikow.
---
Greetings from Bavaria, Germany
Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word XP, Win 98
http://word.mvps.org/
 
H

Helmut Weber

Hi Howard,
whether all of this is necessary for sorting an array
of ubound 20 may be disputable. But it seems, I found
the ultimate expert on sorting. Adding your page to
my favorites' list.
Greetings from Bavaria, Germany
Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word XP, Win 98
http://word.mvps.org/
 
H

Howard Kaikow

Yes, but people develop bad habits rather easily.
I don't like to see folkes encouraged to use bubble sort, even in a one shot
throw away program.
Bad habits are hard to break.
Heck, I still use MSFT Word, that shows how hard it is to break a bad habit!
 
H

Helmut Weber

Hi Howard,
ok, I'd like to do away with bad habits, too.
Then, what method would you recommend,
if you don't know anything about what should be sorted.
Quicksort? Or nothing at all, and try to get some information
about the data in question beforehand. But what information?
Cheers,
Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word XP, Win 98
http://word.mvps.org/
 
D

D

Thanks a lot for all the information, both of you. By the way, it's sorting
a 2-dimensional array by date in yyyy.mm.dd format (to answer one of Helmut's
implied questions, hehe). Looks like I should be able to find more than what
I need on your site. Thanks again.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top