Re: More about sorting text lines?
- From: "Randy Birch" <rgb_removethis@xxxxxxxx>
- Date: Fri, 17 Feb 2006 21:38:43 -0500
If there are only a couple of hundred entries that is fine for loading the
array. You could also do it in one call retrieving the data into a buffer,
then use Split to return an array with each line:
(air code)
dim buff as string
dim a() as string
dim hfile as long
hFile = FreeFile
Open sFilename For Input As #hFile
buff = Input$(LOF(hFile), hFile)
Close #hFile
a() = split(buff, vbCrLf)
quicksortdecending a(), lbound(a), ubound(a)
for cnt = lbound(a) to ubound(a)
list1.additem a(cnt)
next
.... and later, to sort the other way
quicksortascending a(), lbound(a), ubound(a)
list1.clear
for cnt = lbound(a) to ubound(a)
list1.additem a(cnt)
next
the two quicksort routines can be found here:
http://vbnet.mvps.org/code/sort/qsvariations.htm. In that demo the two sort
functions to use are called "QuickSortStringsAscending" and
"QuickSortStringsDescending"
--
Randy Birch
MS MVP Visual Basic
http://vbnet.mvps.org/
Please reply to the newsgroups so all can participate.
"Rob Barnes" <r.barnes@xxxxxxxxx> wrote in message
news:dt55hj$ntm$1@xxxxxxxxxxxxxxxxxxx
: I've searched VB after replies about sorting lines of data in a listbox in
: decending order. One solution was to hide an unsorted listbox and fill it
in
: reverse order. Alternatively, I think the following fills a string array,
: but I'm not clear about the best way to get a list in descending order in
a
: Litstbox after this, assuming this is right. I have opened File1, a .txt
: file containing short lines of text [no punctuation]
:
: Sub FillArray(Absentees, Index)
: While Not EOF(1)
: Input #1, Absentees(Index)
: Index = Index + 1
: Wend
: End Sub
:
: Is this a good way to fill an array, then Quicksort it? How does it get
from
: here to being a list in decending order? Help appreciated.
:
:
.
- References:
- More about sorting text lines?
- From: Rob Barnes
- More about sorting text lines?
- Prev by Date: Re: OPEN FILES IN THE SAME SESSION
- Next by Date: Re: OPEN FILES IN THE SAME SESSION
- Previous by thread: More about sorting text lines?
- Next by thread: M$Inet control apparently SUCKS (or is it me) WTF????
- Index(es):
Relevant Pages
|