Re: More about sorting text lines?



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.
:
:

.



Relevant Pages

  • Re: non-recursive quicksort for 2-D arrays?
    ... You are saying don't use a quicksort as it causes stack problems, but use a Shell Sort, which doesn't ... bigger parts of the array, ... Dim lArrayChunk As Long ...
    (microsoft.public.vb.general.discussion)
  • Re: Fastcode poll - Should Sort include worst case situations
    ... median algorithm, not O), there exists sequences that will beat ... quicksort and make it O. ... by many compiler vendors is "Engineering a Sort ... If it detects that a portion of an array is responding badly, ...
    (borland.public.delphi.language.basm)
  • [PATCH] lib/qsort
    ... This patch introduces an implementation of qsort to lib/. ... I've benchmarked many variants of quicksort implementations on array sizes ... +void qsort_swap ...
    (Linux-Kernel)
  • Re: Read headings from CSV into Form in VBA?
    ... They want to have 4 top heading categories which you can only ... Spliteach line on the separator to derive an array of elements. ... Public Function ReadFile(ByVal FileName As String) As String ... Dim hFile As Long ...
    (microsoft.public.office.developer.vba)
  • Re: Help using a C dll function in VB
    ... same prototype, it can turn the array, like above. ... private hfile as inptr ... public shared function openmp4as boolean ...
    (microsoft.public.dotnet.languages.vb)