TIP: Click on subject to list as thread! ANSI
echo: locuser
to: All
from: Bob Lawrence
date: 1997-04-29 13:09:04
subject: File Sort

Hi all,
        I wrote a macro in WordBasic which needed to load a directory
of sorted files into a dialog array, and I've always thought there had
to be a neat way to sort the files as they go into the array, rather
than do it twice. This is it.

  WordBasic is a bit agricultural. There is no break command so I've
had to use GOTO (I *love* GOTO, Paul), and instead of findfirst,
findnext in C, or Dir$() in VB, WordBasic uses Files$().

  All I do is load the first filename into the aray (to avoid a nul),
then check the next filename against the array from the top-down,
moving them all up one until I find one that isn't larger. Then I
write the new filename one-up... unless it's the 0-th in the array in
which case I write it there. That way, if the files are already
sorted, I don't have to do anything but write the names in.  

  It's pretty quick...

'     FILENAMES SORT ARRAY
Dim ary$(64)
n = 0
ary$(0) = Files$("*.doc")
While 1 = 1
  f$ = Files$()
  If f$ = "" Then Goto OUT
  For x = n To 0 Step - 1
    If f$ < ary$(x) Then    
      ary$(x + 1) = ary$(x)
      If x = 0 Then ary$(x) = f$
    Else
      ary$(x + 1) = f$
      Goto BREAK
    End If
  Next x
BREAK:
  n = n + 1
Wend
OUT:

Regards,
Bob
___ Blue Wave/QWK v2.12
@EOT:

---
* Origin: Precision Nonsense, Sydney (3:711/934.12)
SEEN-BY: 711/934 712/610
@PATH: 711/934

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.