Alphabetizer FUNCTION

 BBS: Inland Empire Archive
Date: 12-13-92 (01:55)             Number: 293
From: JOE NEGRON                   Refer#: NONE
  To: MARK BUTLER                   Recvd: NO  
Subj: Alphabetizer FUNCTION          Conf: (2) Quik_Bas
MB> Once upon a time Joe Negron uttered these sage words to Shane Header:
                                              ~~~~
Gee, thanks! <g>

JN> What you need is a sort routine.  There are a number of
JN> different sorting methods; here is a relatively simple one,
JN> based on the Bubble Sort, called a "Comb" sort:

MB> How would you combine two string arrays? I am writing a program that
  > needs to combine the filespec matches from the current directory with
  > those found in another into one filename array and display the result
  > for a tag-list. I came up with something that halfway works but
  > looking back over my spaghetti pile of code I figgered "there has to
  > be any easier, cleaner way than this!" ... you know of an easy way to
  > append two such arrays?

Hmmm...on first thought, something like the following seems reasonable:
============================== Begin code ==============================
'Given:
'   CurMatches$() holds the filenames found in the current directory
'   OtherMatches$() holds the filenames found in another directory

   'Find out how many elements the first array has been DIMensioned to
   NumEls1% = UBOUND(CurMatches$) - LBOUND(CurMatches$) + 1

   'Same for the second
   NumEls2% = UBOUND(OtherMatches$) - LBOUND(OtherMatches$) + 1

   'DIMension another array to a size sufficient to hold the contents of
   'the first two arrays
   REDIM File$(1 TO NumEls1% + NumEls2%)

   'Copy the contents of the first array to our new array
   FOR X% = 1 TO NumEls1%
      File$(X%) = CurMatches$(X%)
   NEXT X%

   'Ditto for the second array
   FOR Y% = NumEls1% + 1 TO NumEls1% + NumEls2%
      File$(Y%) = OtherMatches$(Y% - NumEls1%)
   NEXT Y%
=============================== End code ===============================
I am making a few assumptions here:

   1. You don't know before-hand (before program execution) how many
      files are going to be found for each array.

   2. You don't want to do anything "non-standard" like copying blocks
      of memory around (I don't really know how to handle something like
      that for this situation anyway).

   3. You want to preserve the first two arrays.

   4. You realize that this code has been entered "on-line" (i.e.: I
      haven't tested it! <g>).

Of course, as with most programming problems, there is more than one way
to solve this; if you are using PDS, you could use the PRESERVE keyword
to REDIMension the first array to a size sufficient to hold both:
============================== Begin code ==============================
   'Find out how many elements the first array has been DIMensioned to
   NumEls1% = UBOUND(CurMatches$) - LBOUND(CurMatches$) + 1

   'Same for the second
   NumEls2% = UBOUND(OtherMatches$) - LBOUND(OtherMatches$) + 1

   'REDIMension the first array to a size sufficient to hold the
   'contents of the first and second arrays
   REDIM PRESERVE CurMatches$(1 TO NumEls1% + NumEls2%)

   FOR X% = NumEls1% + 1 TO NumEls1% + NumEls2%
      CurMatches$(X%) = OtherMatches$(X% - NumEls1%)
   NEXT X%
=============================== End code ===============================
The PRESERVE keyword allows you to REDIMension an array without clearing
it's contents.

Let me know if this helps.

                                --Joe in Bay Ridge, Brooklyn, NY--
                                      Sun  12-13-1992, 01:33

 * SLMR 2.1a * I'm sure it's clearly explained in the Zmodem DOC's.

--- Maximus 2.01wb
 * Origin: * BlueDog BBS * (212) 594-4425 * NYC FileBone Hub (1:278/709)
Outer Court
Echo Basic Postings

Books at Amazon:

Back to BASIC: The History, Corruption, and Future of the Language

Hackers: Heroes of the Computer Revolution (including Tiny BASIC)

Go to: The Story of the Math Majors, Bridge Players, Engineers, Chess Wizards, Scientists and Iconoclasts who were the Hero Programmers of the Software Revolution

The Advent of the Algorithm: The Idea that Rules the World

Moths in the Machine: The Power and Perils of Programming

Mastering Visual Basic .NET